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

ZOJAC|POJRE?高手帮忙!

Posted by xiao1590 at 2007-03-16 10:58:12 on Problem 1328
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

struct point
{
	double l;
	double r;
};

typedef struct point creatpoint;

int cmp(const void *a , const void *b) 
{ 
	creatpoint *x=(point *)a;
	creatpoint *y=(point *)b;
	return x->r > y->r ? 1:-1;
}

inline bool change(double &a, double &b, double r)
{
	double tmp;
	if (b>r)
		return false;
	tmp=sqrt(r*r-b*b);
	b=tmp+a;
	a=-tmp+a;
	return true;
}

void main()
{
	int i,n,ks=1,radars;
	double d,now;
	creatpoint p[1005];
	while (cin>>n>>d && n)
	{
		radars=0;
		for (i=0; i<n; i++)
		{
			cin>>p[i].l>>p[i].r;//由坐标计算过该点的圆在X轴上圆心的范围,便于贪心
			if (!change(p[i].l, p[i].r, d))
			{
				radars=-1;
				break;
			}
		}
		if (radars!=-1)
		{
			qsort(p,n,sizeof(p[0]),cmp);//排序
			now=p[0].l-1;
			for (i=0; i<n; i++)
			{
				if (now<p[i].l)
				{
					now=p[i].r;
					radars++;
				}
			}
		}
		cout<<"Case "<<ks++<<": "<<radars<<endl;
	}
}

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