zoj 1203 Swordfish【prim】

//zoj1203

你们什么都没看到。。。下边的都是错觉,是错觉,错觉,嗯、、、、、、

  
  
  
  
               
               
               
               
               
               
               
               
               
               
               
               
               
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <algorithm> #define INT_MAXl 2100000000 using namespace std; int n; double map[101][101], v[101][2], lmin[101]; int next[101]; bool flag[101]; int find_min(int x) { int i; lmin[x] = INT_MAXl; int _next = x; for(i=0; i<n; i++) if(flag[i] && map[x][i] < lmin[x]) { lmin[x] = map[x][i]; _next = i; } return _next; } int main() { int i, j, cases=0; double p, q, ans; scanf("%d", &n); while( n) { if( !n )break; ans = 0; for(i=0; i<n; i++) scanf("%lf%lf", &v[i][0], &v[i][1]); for(i=0; i<n; i++) for(j=i+1; j<n; j++) { p = v[i][0] - v[j][0]; q = v[i][1] - v[j][1]; map[j][i] = map[i][j] = sqrt(p * p + q * q); } memset(flag, true, sizeof(flag) ); flag[0] = false; int latest; double w_min; while(1) { w_min = INT_MAXl; latest = -1; for(i=0; i<n; i++) { if( flag[i] == false) { next[i] = find_min(i); if(next[i] != i && w_min > lmin[i] ) { w_min = lmin[i]; latest = next[i]; } } } if( latest == -1) break; flag[ latest ] = false; ans += w_min; } printf("Case #%d:\nThe minimal distance is: %.2lf\n", ++cases, ans); scanf("%d", &n); if(n)printf("\n"); } return 0; }


2604335 2011-07-29 08:50:20 Presentation Error 1203 C++ 0 264 ylwh!
2604330 2011-07-29 08:42:52 Presentation Error 1203 C++ 0 264 ylwh!
2604328 2011-07-29 08:34:57 Presentation Error 1203 C++ 0 264 ylwh!
2602919 2011-07-28 08:28:32 Wrong Answer 1203 C++ 0 264 ylwh!
2602918 2011-07-28 08:28:24 Compilation Error 1203 C 0 0 ylwh!
2602718 2011-07-27 21:45:10 Wrong Answer 1203 C++ 0 264 ylwh!
2602715 2011-07-27 21:44:43 Compilation Error 1203 C 0 0 ylwh!
2602563 2011-07-27 20:14:27 Wrong Answer 1203 C++ 0 264 ylwh!
2602556 2011-07-27 20:12:16 Compilation Error 1203 C++ 0 0 ylwh!
2602548 2011-07-27 20:10:05 Compilation Error 1203 C++ 0 0 ylwh!
2602432 2011-07-27 19:06:07 Wrong Answer 1203 C++ 0 264 ylwh!
2602422 2011-07-27 18:58:57 Wrong Answer 1203 C++ 0 220 ylwh!
2602421 2011-07-27 18:58:44 Compilation Error 1203 C 0 0 ylwh!

第一个最小生成树、、、

你可能感兴趣的:(c,distance,compilation)