| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
直接用atan算出来的角度排序为什么不对呢。。山东理工的OJ上都AC了的嘛。。#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#define pi 3.14159265358979323846
using namespace std;
struct point
{
double x;
double y;
double cita;
};
point pt[10000];
bool cmp(point a,point b)
{
return a.cita<b.cita;
}
int main()
{
int n=0,i;
double x,y,temp;
while(scanf("%lf%lf",&x,&y)!=EOF)
{
pt[n].x=x;
pt[n].y=y;
temp=fabs(y/x);
if(x>0&&y>0)
pt[n].cita=(atan(temp))/pi*180;
if(x>0&&y<0)
pt[n].cita=-(atan(temp))/pi*180;
if(x<0&&y<0)
pt[n].cita=(atan(temp))/pi*180-180;
if(x<0&&y>0)
pt[n].cita=180-(atan(temp))/pi*180;
n++;
}
sort(pt+1,pt+n,cmp);
for(i=0;i<n;i++)
cout<<"("<<pt[i].x<<","<<pt[i].y<<")"<<endl;
//","<<pt[i].cita<<
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator