Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

直接用atan算出来的角度排序为什么不对呢。。山东理工的OJ上都AC了的嘛。。

Posted by bingshen at 2011-02-01 22:52:18 on Problem 2007
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator