[恢]hdu 1785

2011-12-21 09:46:27

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1785

题意:中文。给点和原点连线与x轴夹角排序。

代码:

# include <stdio.h>
# include <stdlib.h>


typedef struct point{
double x, y ;
}point ;


point pt[110] ;


int cmp(const void *a, const void *b)
{
double x1 = ((point*)a)->x, y1 = ((point*)a)->y ;
double x2 = ((point*)b)->x, y2 = ((point*)b)->y ;
double diff = x2*y1 - x1*y2 ;
if (diff < 1e-9 && diff >-1e-9) return 0 ;
else if (diff < 0) return -1 ;
else return 1 ;
}


int main ()
{
int flag, n, i ;
while (~scanf ("%d", &n) && n >= 0)
{
for (i = 0 ; i < n ; i++)
scanf ("%lf%lf", &pt[i].x, &pt[i].y) ;
qsort(pt, n, sizeof(point), cmp) ;
flag = 0 ;
for (i = 0 ; i < n ; i++)
{
if (flag == 0) flag =1 ;
else printf (" ") ;
printf ("%.1lf %.1lf", pt[i].x, pt[i].y) ;
}
printf ("\n") ;
}
return 0 ;
}



posted @ 2012-01-06 23:22  Seraph2012  阅读(129)  评论(0编辑  收藏  举报