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 |
读题啊兄弟们!老兄们!我鄙视我自己!WA的都进来看看【附代码】Stone #1 is Freddy's stone, stone #2 is Fiona's stone 鄙视自己啊。。。很习惯性的计算从0到n-1的最长长度了...鄙视啊...附代码... #include <iostream> #include <cmath> using namespace std; #define inf 999999999; const int NN=3000; double posi[NN][2]; double map[NN][NN]; int n; double poww(double a) { return a*a; } double max(double a,double b) { if (a>b) return a; return b; } int main() { int u=0; while (scanf("%d",&n),n!=0) { ++u; for (int i=0;i<n;++i) { scanf("%lf%lf",&posi[i][0],&posi[i][1]); for (int j=0;j<i;++j) map[i][j]=map[j][i]=sqrt(poww(posi[i][0]-posi[j][0]) + poww(posi[i][1]-posi[j][1])); map[i][i]=0; } int i,j,k; double ans[NN]; for (int i=0;i<n;++i) ans[i]=inf; bool v[NN]; memset(v,0,sizeof(v)); for (ans[0]=0,j=0;j<n;++j) { for (k=-1,i=0;i<n;++i) if (!v[i] && (k==-1 || ans[i]<ans[k])) k=i; for (v[k]=1,i=0;i<n;++i) if (!v[i] && max(ans[k],map[k][i])<ans[i]) ans[i]=max(ans[k],map[k][i]); } printf("Scenario #%d\nFrog Distance = %.3lf\n\n",u,ans[1]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator