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 |
A多次和WA多次终于找到差别,int i在里面还是外面,求解释下面这个代码是A的: #include<iostream> #include<math.h> using namespace std; int main(void) { int i,j; double x,y; double left[1000],right[1000]; double n,d; while(true) { cin>>n>>d; if(n==0 && d==0) break; static int count=1; bool flag=true; for(i=0;i<n;i++) { cin>>x>>y; left[i]=x-sqrt(d*d-y*y); right[i]=x+sqrt(d*d-y*y); if(y>d) flag=false; } if(flag==false) { cout<<"Case "<<count++<<": -1"<<endl; continue; } double temp; for(i=0;i<n;i++) for(j=i;j<n;j++) if(right[i] > right[j]) { temp=right[i]; right[i]=right[j]; right[j]=temp; temp=left[i]; left[i]=left[j]; left[j]=temp; } int radar=1; for(i=0,temp=right[0];i<n-1;i++) { if(left[i+1] > temp)//need another dar and it should install at right[i+1] { radar++; temp=right[i+1]; } else if(right[i+1] < temp) //NO. i+1 island has narrow scope so the dar should install right[i+1] temp=right[i+1]; } cout<<"Case "<<count++<<": "<<radar<<endl; } return 0; } 如果去掉开始的int i,j; 而在每次for循环的时候for(int i=...) 这样就WA,请问这是为什么呢? Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator