|
|
back to boardthe rules are not clear Posted by Apiwat 26 Oct 2006 10:14 can x,y be a negative integer? one more thing Posted by Apiwat 26 Oct 2006 10:26 my code fail on test #10 for many times i can't see why? #include<stdio.h> int abs(int n) { if(n>=0) return n; else return -n; } int min(int a,int b) { if(a<=b) return a; else return b; } int main() { int n,i; int best_u_last,best_d_last ,y_u_last,y_d_last ,x1,y1,x2,y2 ,dx;
scanf("%d",&n);
scanf("%d %d %d %d",&x1,&y1,&x2,&y2); y_d_last=y1; y_u_last=y2; best_u_last=x2-x1+y2-y1-4; best_d_last=x2-x1-2;
for(i=1;i<n;i++) { scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
if( (y1>=y_u_last-1) || (y2<=y_d_last+1) ) { //suck!! best_u_last=-1; break; } else { //pass //dx dx=abs(x2-x1); //u best_u_last=min( best_u_last + abs(y_u_last - y2) , best_d_last + abs(y_d_last - y2 + 2) ) + dx; //d best_d_last=min( best_u_last + abs(y_u_last - y1 - 2) , best_d_last + abs(y_d_last - y1) ) + dx; } y_u_last=y2; y_d_last=y1; }
printf("%d", best_u_last ); } |
|
|