Finish 2012-11-07 16:00:00 UTC

AB11020011

by AMITAVA BISWAS

Status: Passed
Results: 10350 (cyc: 14, node: 288)
CPU Time: 34.67
Score: 10759.3
Submitted at: 2012-11-02 06:11:55 UTC
Scored at: 2012-11-02 06:14:45 UTC

Current Rank: 1590th (Highest: 22nd )
Based on: AB11020006 (diff)
Basis for: AB11020018 (diff)
Basis for: AB11020946 (diff)
Basis for: AB11020955 (diff)

Comments
Please login or create a profile.
Code
function xyOut = solver(a, xyIn, wts)
pts=size(xyIn,1); % how many points?
x=xyIn(:,1); y=xyIn(:,2);
xyOut=[x/vectorgcd(x) y/vectorgcd(y)]; % condense if ok
mx=max(xyOut(:,1))-min(xyOut(:,1));
my=max(xyOut(:,2))-min(xyOut(:,2));
xyOut=xyOut+rand(pts,2)*max(mx,my); % expand if on a straight line
% check if necessary?

% xyOut=xyIn;

for n=1:40
    for k=1:pts % test each vertex
        z=xyOut(k,:); % include this point
        for m=1:pts
            if a(k,m) % connected
                z=[z;xyOut(m,:)];
            end
        end
        xyOut(k,:)=mean(z,1);
    end
end
% xyOut(:,1)=xyOut(:,1)-mean(xyOut(:,1))+mean(xyIn(:,1));
% xyOut(:,2)=xyOut(:,2)-mean(xyOut(:,2))+mean(xyIn(:,2));
xyOut=round(xyOut*100);
% normalize and return to original spread/variance?
myloop=1;
while myloop; myloop=0;
    for k=1:pts
        for m=1:pts
            if k==m; continue; end % ignore
            if min(xyOut(k,:)==xyOut(m,:)) % overlap
                myloop=1;
                switch randi(4)
                    case 1; xyOut(k,1)=xyOut(k,1)+1;
                    case 2; xyOut(k,1)=xyOut(k,1)-1;
                    case 3; xyOut(k,2)=xyOut(k,2)+1;
                    case 4; xyOut(k,2)=xyOut(k,2)-1;
                end
            end
        end
    end
end
end

function mygcd = vectorgcd(v)
mygcd=v;
if numel(v)>1;
    mygcd=gcd(v(1),vectorgcd(v(2:end)));
end
end