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

求大神指点代码哪里有问题啊?自己测试几组数据都是对的,结果提交后就WA

Posted by jianghuiyou at 2015-04-05 10:30:10 on Problem 1328
#include <iostream>
#include<math.h>
using namespace std;

struct qujian
{
	int x,y;
	float left;
	float right;
} qu[1010];


int compare(const void * a,const void  *b)
{
	return	(*(qujian *)a).left > (*(qujian *)b).left;
}
int main()
{
	int n,d,casenum=0,num=0,flag=0; //num为雷达布置个数的累积
	while(1)
	{
		cin>>n>>d;
		if(n == 0 && d == 0)	break;
		for(int i=0;i<n;i++)
		{
			float dx;
			cin>>qu[i].x>>qu[i].y;
			dx=sqrt(pow(d*1.0,2)-pow(qu[i].y*1.0,2));
			qu[i].left=qu[i].x-dx;
			qu[i].right=qu[i].x+dx;
		}
		qsort(qu,n,sizeof(qu[0]),compare);
		if(d <= 0)	flag =1;
		for(int i=0;i<n;i++)
		{
			if(qu[i].y > d){
				flag=1;
				break;
			}
		}
		if(flag == 1)
		{
			cout<<"Case "<<++casenum<<": -1"<<endl;
			flag=0;
			continue;
		}
		int j=0;
		while(j<n)
		{
			int m=j+1;
			while(j < n && qu[m].left <= qu[j].right)	m++;
			j=m;
			num++;
		}
		casenum++;
		cout<<"Case "<<casenum<<": "<<num<<endl;
		num=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