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 |
高手们指点一下吧!为什么wa算法:硬币状态 -1:light, 0:normal, 1: heavy. 天平状态 -1:down, 0: even, 1: heavy. 枚举24中可能。 利用 ((coinStatus[input[0][1]] + coinStatus[input[0][2]] + coinStatus[input[0][3]]+ coinStatus[input[0][4]] - coinStatus[input[0][5]] - coinStatus[input[0][6]] - coinStatus[input[0][7]]-coinStatus[input[0][8]] == input[0][0]) 这种方法判断枚举是否正确。 #include<iostream> using namespace std; void main() { char line1[5] = {'0'}; char line2[5] = {'0'}; char line3[5] = {'0'}; int input[3][9]; int coinStatus[12] = { 0 }; int nn = 0; cin >> nn; while (nn--){ for(int i = 0; i < 3; i++) { cin >> line1 >> line2 >> line3; for(int j = 1; j < 5; j++) { input[i][j] = line1[j-1] - 65;} for(int k = 1; k < 5; k++) { input[i][k+4] = line2[k-1] - 65;} switch (*line3) { case 'e' : input[i][0] = 0; break; case 'd' : input[i][0] = -1; break; case 'u' : input[i][0] = 1; break; default: ; } } int index = 0; for(index = 0; index < 12; index ++) { coinStatus[index] = 1; if((coinStatus[input[0][1]]+coinStatus[input[0][2]]+coinStatus[input[0][3]]+coinStatus[input[0][4]] -coinStatus[input[0][5]]-coinStatus[input[0][6]]-coinStatus[input[0][7]]-coinStatus[input[0][8]] == input[0][0]) && (coinStatus[input[1][1]]+coinStatus[input[1][2]]+coinStatus[input[1][3]]+coinStatus[input[1][4]] -coinStatus[input[1][5]]-coinStatus[input[1][6]]-coinStatus[input[1][7]]-coinStatus[input[1][8]] == input[1][0]) && (coinStatus[input[2][1]]+coinStatus[input[2][2]]+coinStatus[input[2][3]]+coinStatus[input[2][4]] -coinStatus[input[2][5]]-coinStatus[input[2][6]]-coinStatus[input[2][7]]-coinStatus[input[2][8]] == input[2][0])) cout << (char)(index + 65) << " is the counterfeit coin and it is heavy. " << endl; coinStatus[index] = -1; if((coinStatus[input[0][1]]+coinStatus[input[0][2]]+coinStatus[input[0][3]]+coinStatus[input[0][4]] -coinStatus[input[0][5]]-coinStatus[input[0][6]]-coinStatus[input[0][7]]-coinStatus[input[0][8]] == input[0][0]) && (coinStatus[input[1][1]]+coinStatus[input[1][2]]+coinStatus[input[1][3]]+coinStatus[input[1][4]] -coinStatus[input[1][5]]-coinStatus[input[1][6]]-coinStatus[input[1][7]]-coinStatus[input[1][8]] == input[1][0]) && (coinStatus[input[2][1]]+coinStatus[input[2][2]]+coinStatus[input[2][3]]+coinStatus[input[2][4]] -coinStatus[input[2][5]]-coinStatus[input[2][6]]-coinStatus[input[2][7]]-coinStatus[input[2][8]] == input[2][0])) cout << (char)(index + 65) << " is the counterfeit coin and it is light. " << endl; coinStatus[index] = 0; } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator