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

谢谢大牛的测试数据很给力!付一下代码!如有雷同我就去死!

Posted by chenxuan123456789 at 2012-09-17 11:35:32 on Problem 1328
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef struct node
{
	double s;
	double e;
}Node;
Node p[1010];
int cmp(const void *_a,const void *_b)
{
	Node *a=(Node*)_a;
	Node *b=(Node*)_b;
	if(fabs(a->s-b->s)==1e-10)
	{
		if(a->e<b->e)
			return 1;
		else
			return -1;
	}
	else
	{
		if(a->s>b->s)
			return 1;
		else
			return -1;
	}
}
int main()
{
	int n,i,times=1,flag,ans,d;
	double x,y,t;
	while(scanf("%d %d",&n,&d)!=EOF)
	{
		if(n==0&&d==0)
		break;
		flag=0;
		for(i=0;i<n;i++)
		{
			scanf("%lf %lf",&x,&y);
            if(y>abs(d))
			flag=1;
			else
			{
				p[i].s=x-sqrt(d*d-y*y);
				p[i].e=x+sqrt(d*d-y*y);
			}
		}
		if(flag||d<0)
		{
			printf("Case %d: -1\n",times++);
			continue;
		}
		qsort(p,n,sizeof(p[0]),cmp);
		ans=1;
        t=p[0].e;
		for(i=1;i<n;i++)
		{
			if(p[i].e<t)
				t=p[i].e;
			else
			{
				if(p[i].s>t)
				{
				t=p[i].e;
				ans++;
				}
			}
		}
	printf("Case %d: %d\n",times++,ans);
	}
	return 1;
}
 

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