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

why? why? why?

Posted by hutu_2000 at 2009-03-20 11:23:35 on Problem 1328
这怎么会错呢,我从网上找了几个人的代码,和我的也没什么不同啊?
也不知道哪里错了,于是到处乱改,结果还是错的,朋友们,帮帮忙吧!

代码如下:
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
struct point
{
	double a,b;
};
bool cmp(point x,point y)
{
	if(abs(x.a-y.a)<1e-8) return x.b-y.b<0;
	else return x.a-y.a<0;
}
int main()
{
	int n,i,j,s[1001];            //s记录灯的位置
	point st[1001];
	int h;
	for(j=1;scanf("%d %d",&n,&h)==2&&!(n==0&&h==0);j++)
	{
		int p=0;
		if(h<=0) p=-1;
		for(i=0;i<n;i++)
		{
			int x,y;
			scanf("%d %d",&x,&y);
			if(h<y)                       //别写反了
				p=-1;
		    else
			{ 
			    st[i].a=x-sqrt(h*h-y*y*1.0);
			    st[i].b=x+sqrt(h*h-y*y*1.0);
			} 
		} 
		if(p!=-1)
		{
			sort(st,st+n,cmp);
		    s[p++]=st[n-1].a;
		    for(i=n-2;i>=0;i--)
			{
				if(s[p-1]-st[i].b>1e-8)         //???
					s[p++]=st[i].a;
			}
		}
		printf("Case %d: %d\n",j,p);                  
	}
	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