标签:des style blog http color java os io strong
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1875
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 15473 Accepted Submission(s):
4791
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 using namespace std; 5 double map[1010][1010],node[1010],s,Min; 6 int m,flag; 7 const double INF=999999; 8 9 void prim() 10 { 11 int vis[1010]= {0}; 12 int tm=1,v=1; 13 flag=0; 14 s=0; 15 vis[tm]=1; 16 node[tm]=0; 17 for (int k=1; k<=m; k++) 18 { 19 Min=INF; 20 for (int i=1; i<=m; i++) 21 if (!vis[i]) 22 { 23 //cout<<node[i]<<" "<<map[tm][i]<<endl; 24 if(node[i]>map[tm][i]&&map[tm][i]>=10&&map[tm][i]<=1000) 25 node[i]=map[tm][i]; 26 if (Min>node[i]) 27 { 28 Min=node[i]; 29 v=i; 30 31 } 32 } 33 //s+=node[v]; 34 vis[v]=1; 35 tm=v; 36 } 37 for (int i=1; i<=m; i++) 38 { 39 s+=node[i]; 40 if (node[i]!=INF) 41 flag++; 42 } 43 } 44 45 int main () 46 { 47 int n,a[1010],b[1010]; 48 cin>>n; 49 while (n--) 50 { 51 //memset (map,INF,sizeof (map)); 52 cin>>m; 53 for (int i=1; i<=m; i++) 54 { 55 cin>>a[i]>>b[i]; 56 } 57 for(int i=1; i<=m; i++) 58 { 59 node[i]=INF; 60 for (int j=1; j<=m; j++) 61 { 62 map[i][j]=map[j][i]=sqrt((double)((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]))); 63 } 64 } 65 prim(); 66 if (flag==m) 67 printf ("%.1lf\n",s*100); 68 else 69 printf ("oh!\n"); 70 } 71 return 0; 72 }
标签:des style blog http color java os io strong
原文地址:http://www.cnblogs.com/qq-star/p/3932559.html