Skip to content

Instantly share code, notes, and snippets.

@balamark
Created May 12, 2015 17:25
Show Gist options
  • Select an option

  • Save balamark/ff5dfb4b2c0c26cca8d6 to your computer and use it in GitHub Desktop.

Select an option

Save balamark/ff5dfb4b2c0c26cca8d6 to your computer and use it in GitHub Desktop.
retrospect
int ans=55;
for(int tryc=0;tryc<N;++tryc){
for(int cntr: vc){ // here I try to squeeze other ducks toward this center duck
int t=0; //tmp ans
printf("Try col @ %d, center @ %d\n", tryc, cntr);
for(int row: vc){
int up=cntr-1, down=cntr+1;
for(int c=0;c<N;++c) if(grid[row][c]=='o'){
t += abs(c - tryc);
//step toward center:
if(row>cntr){
t += row-down;
down += 1;
}
else if(row<cntr){
t += row-up;
up += 1;
}
}
}
cout<<"="<<t<<endl;
ans = min(ans, t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment