| ||||||||||
| 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 | |||||||||
Re:我的程序不知道什么地方错了!那位兄弟帮着看一下呢?谢谢! <内有程序〉In Reply To:我的程序不知道什么地方错了!那位兄弟帮着看一下呢?谢谢! <内有程序〉 Posted by:Bulrush at 2005-09-13 16:36:45 > #include<iostream>
> #include<cstdio>
> #include<cmath>
> using namespace std;
> float a[1001],b[1001];
> float distance(float x1,float y1,float x2,float y2){
> return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
> }
> int main(){
> float gopherx,gophery,dogx,dogy;
> while(cin>>gopherx>>gophery>>dogx>>dogy){
> bool flag=0;
> float sum=999999,x,y;
> int i=0,j;
> while(scanf("%f%f",a+i,b+i)!=EOF){
> ++i;
> }
> for(j=0;j<=i;++j){
> float d_gopher=distance(gopherx,gophery,a[j],b[j]);
> float d_dog=distance(dogx,dogy,a[j],b[j]);
> if(d_gopher<d_dog/2){
> if(d_gopher<sum){
> sum=d_gopher;
> x=a[j];
> y=b[j];
> flag=1;
>
> }
> }
> }
> if(flag==1){
> cout<<"The gopher can escape through the hole at (";
> printf("%.3f",x);
> cout<<",";
> printf("%.3f",y);
> cout<<")."<<endl;
> }
> if(flag==0){
> cout<<"The gopher cannot escape."<<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