Finish 2010-05-05 12:00:00 UTC

long time no see VIII

by srach

Status: Passed
Results: 17753017 (cyc: 14, node: 689)
CPU Time: 56.988
Score: 35513.7
Submitted at: 2010-04-29 15:17:36 UTC
Scored at: 2010-04-29 15:24:30 UTC

Current Rank: 3312th (Highest: 61st )
Based on: long time no see VII (diff)
Basis for: long time no see IX (diff)

Comments
Alan Chalker
10 May 2010
This entry was submitted during the Darkness phase
Alan Chalker
11 May 2010
This entry gets a result of 24435843 on the test suite (6682826 more than the contest suite). It has a ranking of 3311 compared to all other entries run against the test suite according to the data set provided by Jan Keller.
Please login or create a profile.
Code
function Aest = solver(imageSize, queryLimit)

Aest = zeros(imageSize)-1;

%% calculate window width
w =  ceil(sqrt(imageSize*imageSize./queryLimit));

lmask = true(w,w);
nlmask = ~lmask;

ww = (w)*(w);


cnt = queryLimit;
mask = false(imageSize, imageSize);

for r = 1:w:imageSize-w
    for c= 1:w:imageSize-w
        mask(r:r+w-1, c:c+w-1)= true;

        Aest(r:r+w-1, c:c+w-1) = round(queryImage(mask)/ww);
        cnt = cnt-1;
        mask(r:r+w-1, c:c+w-1)= false;
    end
end
rr = r+w;
cc = c+w;
ss = imageSize-cc;
if ss > 0
    for r = 1:w:imageSize-w
        mask(r:r+w-1, cc:cc+ss-1)= true;
        Aest(r:r+w-1, cc:cc+ss-1) = round(queryImage(mask)/(w)/ss);
        cnt = cnt-1;
        mask(r:r+w-1, cc:cc+ss-1)= false;
    end
    for c = 1:w:imageSize-w
        mask(rr:rr+ss-1, c:c+w-1)= true;
        Aest(rr:rr+ss-1, c:c+w-1) = round(queryImage(mask)/(w)/ss);
        cnt = cnt-1;
        mask(rr:rr+ss-1, c:c+w-1)= false;
    end
        mask(rr:rr+ss-1, cc:cc+ss-1)= true;
        Aest(rr:rr+ss-1, cc:cc+ss-1) = round(queryImage(mask)/(w)/ss);
        cnt = cnt-1;
        mask(rr:rr+ss-1, cc:cc+ss-1)= false;    
end


% 
% id = find(Aest==-1);
% 
% mask = false(imageSize, imageSize);
% for k = 1:min(cnt, length(id))
%         mask(id(k))= true;
%     Aest(id(k)) = queryImage(mask);
%     mask(id(k))= false;
%     cnt=cnt-1;
% end
% 
% mask = false(imageSize, imageSize);
% for k=imageSize*imageSize:-1:imageSize*imageSize-cnt+1
%     mask(k)= true;
%     Aest(k) = queryImage(mask);
%     mask(k)= false;
%   %  cnt = cnt-1;
% end


[idr idc] = find(Aest==-1);

for k = 1:length(idr)
if idr(k)>idc(k)
    Aest(idr(k),idc(k)) = Aest(idr(k)-1, idc(k));
elseif idr(k) < idc(k)
    Aest(idr(k),idc(k)) = Aest(idr(k), idc(k)-1);
end    
end


Aest(Aest==-1) = 255/2;


for r = 2:imageSize-2
    for c = 2:imageSize-2

        Aest(r,c) = round(...
            sum(sum(Aest(r-1:r+1, c-1:c+1)))/9 );
    end
end

Aest2 = ones(size(Aest))*255;
for r = 3:imageSize-3
    for c = 3:imageSize-3
        Aest2(r,c) = round(...
            (2*sum(sum(Aest(r-1:r+1, c-1:c+1)))/9 ...
            -sum(sum(Aest(r-2:r+2, c-2:c+2)))/12)...
        );
%         Aest(r,c) = round(...
%             sum(sum(Aest(r-1:r+1, c-1:c+1)))/9 );
    end
end
mask = false(imageSize, imageSize);
[x,y] = sort(Aest2(:), 'ascend');
for k = 1:cnt
    
    Aest2(y(k)) = 255;
      mask(y(k))= true;
    Aest(y(k)) = queryImage(mask);
    mask(y(k))= false;  

end
% for r = 2:imageSize-2
%     for c = 2:imageSize-2
% 
%         Aest(r,c) = round(...
%             sum(sum(Aest(r-1:r+1, c-1:c+1)))/9 );
%     end
% end

%cnt
% 
% 
% Aest = Aest2;
%cnt