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

AC 用C++,G++不小心就会超时,贴代码

Posted by 452181625 at 2014-05-14 11:16:37 on Problem 1328
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
struct point
{
	double left,right;
};
point p[1005];
bool cmp(point a,point b)
{
	if(a.left!=b.left)
		return a.left<b.left;
	return a.right<b.right;
}
int main()
{
	int n,i,flag,t=1,sum;
	double r,x,y,last;
	while(cin>>n>>r)
	{
		if(n==0&&r==0) break;
		flag=0;
		for(i=1;i<=n;i++)
		{
			cin>>x>>y;
			p[i].left=x-sqrt(r*r-y*y);
			p[i].right=x+sqrt(r*r-y*y);
			if(y>r) flag=1;
		}
		cout<<"Case "<<t++<<": ";
		if(flag)
		{
			cout<<"-1"<<endl;
			continue;
		}
		sort(p+1,p+n+1,cmp);
		sum=1;
		last=p[1].right;
		for(i=2;i<=n;i++)
		{
			if(last>p[i].right)
				last=p[i].right;
			else if(last<p[i].left)
			{
				sum++;
				last=p[i].right;
			}
		}
		cout<<sum<<endl;
	}
	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