|
|
back to boardPLZ HELP ME! WA IN TEST #2 I have seen postts before, but I can0t understand why my code is wrong! plz if someone can give me some hint I would appreciate very much here is my code: #include <stdio.h> double x[103],y[103],x2[103],y2[103],xp,yp; int vx[5],vy[5],d[103],ord[103]; swap(int a, int b){ int tmp=d[a],tmp2=ord[a]; d[a]=d[b];ord[a]=ord[b]; d[b]=tmp;ord[b]=tmp2; } sort(int n){ int i,j; for(i=0;i<n;i++) for(j=0;j<n;j++) if(d[i]<d[j]) swap(i,j); } calc_v(int n){ if(x[n]<x2[n]){ vx[1]=vx[3]=x[n]; vx[2]=vx[4]=x2[n]; } else if (x[n]>=x2[n]){ vx[1]=vx[3]=x2[n]; vx[2]=vx[4]=x[n]; } if(y[n]<y2[n]){ vy[1]=vy[2]=y[n]; vy[3]=vy[4]=y2[n]; } else if (y[n]>=y2[n]){ vy[1]=vy[2]=y2[n]; vy[3]=vy[4]=y[n]; } } dist(int n){ if(xp>=vx[1] && xp<=vx[2]){ if(yp>vy[3]) d[n]=abs(yp-vy[3]); else if (yp<vy[1]) d[n]=abs(vy[1]-yp); else d[n]=0; } else if(yp>=vy[1] && yp<=vy[3]){ if(xp>vx[2]) d[n]=abs(xp-vx[2]); else if (xp<vx[1]) d[n]=abs(vx[1]-xp); else d[n]=0; } else{ if(xp<vx[1]){ if(yp<vy[1]) d[n]=sqrt(abs(xp-vx[1])*abs(xp-vx[1]) + abs(vy[1]-yp)*abs(vy[1]-yp)); else if (yp>=vy[3]) d[n]=sqrt(abs(xp-vx[3])*abs(xp-vx[3]) + abs(vy[3]-yp)*abs(vy[3]-yp)); } else if (xp>vx[2]){ if(yp>vy[4]) d[n]=sqrt(abs(yp-vy[4])*abs(yp-vy[4]) + abs(xp-vx[4])*abs(xp-vx[4])); else if (yp<vy[2]) d[n]=sqrt(abs(vy[2]-yp)*abs(vy[2]-yp) + abs(xp-vx[2])*abs(xp-vx[2])); } } } int main() { int n,i; scanf("%d",&n); for(i=0;i<n;i++) scanf("%Lf %Lf %Lf %Lf",&x[i],&y[i],&x2[i],&y2[i]); scanf("%Lf %Lf",&xp,&yp); for(i=0;i<n;i++){ calc_v(i); dist(i); } for(i=0;i<n;i++) ord[i]=i; sort(n); n--; for(i=0;i<n;i++) printf("%d ",ord[i]+1); printf("%d\n",ord[n]+1); return 0; } Re: PLZ HELP ME! WA IN TEST #2 Try test: 1 0 0 3 1 0 -1 answer isn't 1 ;) keyword to solve this problem is "SQUARE" not rectangle;) Re: PLZ HELP ME! WA IN TEST #2 I don't understand is valid this input?... I thought there are only squares in the input thanks for the reply anyway! |
|
|