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 |
prim水过RE一次,居然是二维字符数组行列打反了。。。 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #define inf 0x3f3f3f3f using namespace std; int n; int arr[2117][2117]; int low[2117], vis[2117]; char item[2117][10]; int prim(){ int i, j, k, sum = 0, pos, minc = inf; vis[1] = 1, pos = 1; for(i = 1; i <= n; i++){ if(i != pos){ low[i] = arr[pos][i]; } } for(i = 2; i <= n; i++){ minc = inf; for(j = 1; j <= n; j++){ if(vis[j] != 1 && low[j] < minc){ minc = low[j]; pos = j; } } vis[pos] = 1; sum += minc; for(j = 1; j <= n; j++){ if(vis[j] != 1 && arr[pos][j] < low[j]){ low[j] = arr[pos][j]; } } } return sum; } int main(){ int i, j, k; while(scanf("%d", &n) != EOF && n != 0){ memset(arr, 0, sizeof(arr)); memset(item, 0, sizeof(item)); memset(low, 0, sizeof(low)); memset(vis, 0, sizeof(vis)); for(i = 1; i <= n; i++){ scanf("%s", item[i]); } for(i = 1; i <= n; i++){ for(j = i; j <= n; j++){ for(k = 0; k < 7; k++){ if(item[i][k] != item[j][k]){ arr[i][j]++; arr[j][i]++; } } } } // for(i = 1; i <= n; i++){ // printf("%s\n", item[i]); // } // for(i = 1; i <= n; i++){ // for(j = 1; j <= n; j++){ // printf("%d ", arr[i][j]); // } // printf("\n"); // } printf("The highest possible quality is 1/%d.\n", prim()); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator