Please help, what's wrong with this program i don't really sure if i understand the problem correctly , but his is my program. plase have a look #include <stdio.h> #include <stdlib.h> struct co { double x,y; int id; }; int cmp(const void *a, const void *b) { co p=*((co *)a); co q=*((co *)b); double result=p.x*q.y-p.y*q.x; if (result>0) return 1; else if (result<0) return -1; else return 0; } void main() { const int maxsize=10000; co p[maxsize]; int i,j,k; int size; #ifndef ONLINE_JUDGE freopen("1207.in","r",stdin); freopen("1207.out","w",stdout); #endif scanf("%d",&size); for (i=0; i<size; i++) { scanf("%lf%lf",&(p[i].x),&(p[i].y)); p[i].id=i+1; } qsort(p,size,sizeof(co),cmp); printf("%d %d",p[0].id,p[size/2].id); } Try this test 4 1 1 2 2 1 0 2 0 more please (+) > 4 > 1 1 > 2 2 > 1 0 > 2 0 my program output is 3 2 , what's the correct one and why? it seems like I really misunderstand the problem and I don't know what's the point :( Re: more please (+) Hmm, that's strange. 3 2 is ok, but on my computer it returns 2 4, what is of course wrong. I guess it depends on the realization of qsort. IMHO, your solution is not ok, but I'm not sure. What compiler do you use? Anyway, thanks quite strange , I use Mingw as compiler, it produces correct answer anyway, my old this solution is wrong as you said Re: Please help, what's wrong with this program > i don't really sure if i understand the problem correctly , but his is my > program. plase have a look > > #include <stdio.h> > #include <stdlib.h> > struct co { > double x,y; > int id; > }; > int cmp(const void *a, const void *b) { > co p=*((co *)a); > co q=*((co *)b); > double result=p.x*q.y-p.y*q.x; > if (result>0) > return 1; > else if (result<0) > return -1; > else > return 0; > } > > void main() { > const int maxsize=10000; > co p[maxsize]; > int i,j,k; > int size; > #ifndef ONLINE_JUDGE > freopen("1207.in","r",stdin); > freopen("1207.out","w",stdout); > #endif > scanf("%d",&size); > for (i=0; i<size; i++) { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1111 > scanf("%lf%lf",&(p[i].x),&(p[i].y)); !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (*) > p[i].id=i+1; > } > qsort(p,size,sizeof(co),cmp); > printf("%d %d",p[0].id,p[size/2].id); > } (*) I think the coordinates must be shifted, because the point 0 must be (0, 0) (basis) Re: Please help, what's wrong with this program Posted by kcm1700 27 May 2004 21:23 Edited by author 27.05.2004 21:25 Re: Please help, what's wrong with this program Posted by kcm1700 27 May 2004 21:24 ss |