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 |
很暴力的一道水题,不过有些陷阱要注意……虽然很水,不过要注意: 1.Sally will always place the same number of coins on the right balance as on the left balance 即,天平左右数量是相等的,但数量是随意的,即可能不是4。 2.For each case, the output will identify the counterfeit coin by its letter and tell whether it is heavy or light. The solution will always be uniquely determined. 即,答案是唯一的。 3.枚举,候选的char需满足: 1.在没有该char的地方。必须是even。 2.在有该char的地方,up或者是down需满足候选char的可能值,即要唯一。 水之又水…… 还是贴个代码,仅供参考。 #include <iostream> #include <cstdlib> #include <algorithm> #include <string> #define REP(i,n) for(i=0;i<n;i++) using namespace std; string str[9]; char map[3][5] = {"even","down","up"}; int check(int i) { int j,k,a,b; bool flag; char ch; ch = i + 64; REP(k,2) { flag = false; REP(j,3) { //注意:ch要解释所有非even的情形!!!,即没有ch的一定要是even a = str[j*3].find(ch); //a、b最多只有一个找到了可能的坏币 b = str[j*3+1].find(ch); if( a != string::npos ) { flag = true ; if( str[j*3+2] != map[1+k] ) break; } if( b != string::npos ) { flag = true ; if( str[j*3+2] != map[2-k] ) break; } if( a == b && b == string::npos && str[j*3+2] != map[0] ) return 0; } if( !flag ) return 0; if( j == 3 ) { if( k == 0 ) return -1; else return 1; } } return 0; } int main() { int i,j,k,n; cin>>n; while (n--) { REP(i,9) cin>>str[i]; REP(i,12) { j = check(i+1); if( j != 0 ) { if( j == -1 ) printf("%c is the counterfeit coin and it is light.\n",i+65); else printf("%c is the counterfeit coin and it is heavy.\n",i+65); break; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator