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

数据全过了,怎么会W啊

Posted by wx1166750 at 2006-09-26 22:52:43 on Problem 3021
代码如下:
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

struct ok
{
	int x,y;
};
int a[500][500];
ok b[55];
int main()
{
	int n,w,i,j,m,s,flag,sum;
	queue<ok> q;
	ok temp,ac;
	double t;
	cin>>n;
	for(w=0;w<n;w++)
	{
		cin>>m>>s;
		for(j=0;j<m;j++)
			cin>>b[j].x>>b[j].y;
		memset(a,0,sizeof(a));
		sum=0;
		for(i=0;i<=s;i++)
		{
			t=sqrt(s*s-i*i+0.0);
			if(abs(t-(int)t)==0)
			{
				a[i][(int)t]=-1;
				sum++;
			}
		}
		if(!sum)
		{
			cout<<"not possible"<<endl;
			continue;
		}
		while(!q.empty())
			q.pop();
		temp.x=temp.y=0;
		q.push(temp);
		flag=1;
		while(!q.empty()&&flag)
		{
			temp=q.front();
			q.pop();
			for(i=0;i<m&&flag;i++)
			{
				ac.x=temp.x+b[i].x;
				ac.y=temp.y+b[i].y;
				if(a[ac.x][ac.y]==-1)
				{
					cout<<a[temp.x][temp.y]+1<<endl;
					flag=0;
					break;
				}
				if(ac.x*ac.x+ac.y*ac.y<s*s&&a[ac.x][ac.y]==0)
				{
					a[ac.x][ac.y]=a[temp.x][temp.y]+1;
					q.push(ac);
				}
			}
		}
		if(q.empty())
			cout<<"not possible"<<endl;
	}
	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