Dog and Gopher

// Dog and Gopher.cpp : Defines the entry point for the console application. // #include "stdafx.h" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { bool JudgeEscape(double **H,double gx,double gy,double dx,double dy,int *v,int n); int n=0; double gx=0; double gy=0; double dx=0; double dy=0; while(cin>>n>>gx>>gy>>dx>>dy) { if(n==EOF)break; bool escape=true; int visit=0; double **hole=new double*[n]; for(int i=0;i<n;++i) { hole[i]=new double[2]; cin>>hole[i][0]>>hole[i][1]; } escape=JudgeEscape(hole,gx,gy,dx,dy,&visit,n); if(escape==true)cout<<"The gopher can escape the hole at ( "<<hole[visit][0]<<","<<hole[visit][1]<<" )."<<"/n"; else cout<<"The gopher cannot escape."<<"/n"; for(int i=0;i<n;++i)delete hole[i]; delete []hole; } system("pause"); return 0; } bool JudgeEscape(double **H,double gx,double gy,double dx,double dy,int *v,int n) { double distanceG=0; double distanceD=0; bool flag=false; for(int i=0;i<n;++i) { distanceG=(fabs(gx-H[i][0])*fabs(gx-H[i][0])+fabs(gy-H[i][1])*fabs(gy-H[i][1])); distanceD=(fabs(dx-H[i][0])*fabs(dx-H[i][0])+fabs(dy-H[i][1])*fabs(dy-H[i][1])); if(4*distanceG<distanceD) { *v=i; flag=true; } } return flag; } 

你可能感兴趣的:(delete,System)