ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1207. Median on the Plane

Please help, what's wrong with this program
Posted by MadPsyentist/Sam 22 Mar 2002 18:18
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
Posted by Mephistos 22 Mar 2002 23:29
4
1 1
2 2
1 0
2 0
more please (+)
Posted by MadPsyentist/Sam 23 Mar 2002 02:08
> 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 (+)
Posted by Mephistos 23 Mar 2002 12:35
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
Posted by MadPsyentist/Sam 25 Mar 2002 10:14
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
Posted by Ivannushka 21 Aug 2002 18:39
> 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