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 zhb_msqx at 2007-08-19 15:29:29 on Problem 1328
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;

struct xy{
	int x,y;
} node[1000];
int mark[1000]; //标记雷达是否已经覆盖了

int n,d;

int cmp(const void *a1,const void *a2){
	xy s=*(xy *)a1;
	xy t=*(xy *)a2;
	return (s.x-t.x);
}

int cal(int px,int py){  //返回雷达最右边可能的坐标
	double l=d*d-py*py;
	if(l<0)return -1;
	l=sqrt(l);
	double re=px+l;
	if(re>=0)return (int)re;
	else return ((int)re-1);
}

void main(){
//	ifstream in("data.txt");
	int testcase=1;
	while(1){
		cin>>n>>d;
		if(n==0||d==0)break;
		for(int i=0;i<n;i++){
			cin>>node[i].x>>node[i].y;
		}
		memset(mark,0,sizeof(mark));
		qsort(node,n,sizeof(node[0]),cmp);

		int cur=0;
		bool find=true;

		if(d<0)find=false;//雷达的半径为负

		int radar=0;
		while(cur!=n&&find){
			if(mark[cur]==1){ //如果雷达已经覆盖了这个点就跳过
				cur++;
			}else{
				radar++;
				int mostr=cal(node[cur].x,node[cur].y); //计算这个点最右边的可能的坐标
				if(mostr==-1){
					find=false;  //不存在解
				}else {
					for(int tmp=cur+1;tmp<n;tmp++){          //所有可以被这个x覆盖的点都让它覆盖
						if(((node[tmp].x-mostr)*(node[tmp].x-mostr)+node[tmp].y*node[tmp].y)<=4){
							mark[tmp]=1;
						}
					}
					mark[cur]=1;
					cur++;
				}
			}
		}
		if(find){
			cout<<"Case "<<testcase++<<": "<<radar<<endl;
		}else{
			cout<<"Case "<<testcase++<<": "<<-1<<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