ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1207. Медиана на плоскости

Please help, what's wrong with this program
Послано Sam Green 22 мар 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
Послано Mephistos 22 мар 2002 23:29
4
1 1
2 2
1 0
2 0
more please (+)
Послано Sam Green 23 мар 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 (+)
Послано Mephistos 23 мар 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
Послано Sam Green 25 мар 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
Послано Ivannushka 21 авг 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
Послано Kim, Chan Min 27 май 2004 21:23


Edited by author 27.05.2004 21:25
Re: Please help, what's wrong with this program
Послано Kim, Chan Min 27 май 2004 21:24
ss