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 |
为迷途中的小猫咪们贴个代码#include <iostream> using namespace std; //#define DEBUG //1789 int n, nDist, nIndex; char code[2002 * 7]; char s[2002]; char maps[2002]; int calcDist(int a, int b) { int k, dist; char* i; char* j; if (a == b) return 0; else { dist = 0; i = code + 7 * a; j = code + 7 * b; for (k = 0; k < 7; k++) { if (*i != *j) { dist++; } i++; j++; } return dist; } } void getNearest() { int i, tmpDist; nDist = 100; nIndex = -1; for (i = 1; i < n; i++) { if (maps[i] == 0 && s[i] < nDist) { nDist = s[i]; nIndex = i; } } maps[nIndex] = 1; for (i = 1; i < n; i++) { if (maps[i] == 0) { tmpDist = calcDist(nIndex, i); if (tmpDist < s[i]) s[i] = tmpDist; } } } int process() { int i, index; int l = 0; s[0] = 0; maps[0] = 1; for (i = 1; i < n; i++) { s[i] = calcDist(0, i); maps[i] = 0; } for (i = 0; i < n - 1; i++) { getNearest(); l += nDist; } return l; } int main(int argc, char *argv[]) { int i, j, ans; while (1) { cin >> n; if (n == 0) { break; } for (i = 0; i < n ; i++) { scanf("%s", code + i * 7); } code[7 * n] = '\0'; ans = process(); cout << "The highest possible quality is 1/" << ans << "." << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator