Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
数据全过了,怎么会W啊代码如下: #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator