标签:des style blog http color os java io strong
4 aaaaaaa baaaaaa abaaaaa aabaaaa 0
The highest possible quality is 1/3.
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 int n,mp[2010][2010],d[2010]; 18 char s[2010][10]; 19 bool done[2010]; 20 priority_queue< pii,vector< pii >,greater< pii > >q; 21 int calc(int i,int j){ 22 int tmp = 0; 23 for(int k = 0; k < 7; k++) 24 if(s[i][k] != s[j][k]) tmp++; 25 return tmp; 26 } 27 int prim(){ 28 int ans = 0; 29 for(int i = 0; i <= n; i++){ 30 done[i] = false; 31 d[i] = INF; 32 } 33 while(!q.empty()) q.pop(); 34 d[1] = 0; 35 q.push(make_pair(d[1],1)); 36 while(!q.empty()){ 37 int u = q.top().second; 38 int w = q.top().first; 39 q.pop(); 40 if(done[u]) continue; 41 done[u] = true; 42 ans += w; 43 for(int i = 1; i <= n; i++){ 44 if(d[i] > mp[u][i]){ 45 d[i] = mp[u][i]; 46 q.push(make_pair(d[i],i)); 47 } 48 } 49 } 50 return ans; 51 } 52 int main() { 53 int i,j; 54 while(scanf("%d",&n),n){ 55 for(i = 0; i <= n; i++){ 56 for(j = 0; j <= n; j++) 57 mp[i][j] = INF; 58 } 59 for(i = 1; i <= n; i++) 60 scanf("%s",s[i]); 61 for(i = 1; i <= n; i++){ 62 for(j = i+1; j <= n; j++) 63 mp[i][j] = mp[j][i] = calc(i,j); 64 } 65 printf("The highest possible quality is 1/%d.\n",prim()); 66 } 67 return 0; 68 }
标签:des style blog http color os java io strong
原文地址:http://www.cnblogs.com/crackpotisback/p/3940796.html