POJ 1013:counterfeit Dollar

Source: Internet
Author: User

Counterfeit Dollar
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 42028 Accepted: 13369

Description

Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins is true silver dollars; One coin is counterfeit even though their color and size make it indistinguishable from the real silver dollars. The counterfeit coin have a different weight from the other coins and Sally does not know if it's heavier or lighter than The real coins.
Happily, Sally had a friend who loans she a very accurate balance scale. The friend would permit Sally three weighings to find the counterfeit coin. For instance, if Sally weighs-coins against each of the other and the scales balance then she knows these both coins is true. Now if Sally weighs
One of the true coins against a third coin and the scales do not balance then Sally knows the third coin was counterfeit an D She can tell whether it's light or heavy depending on whether the balance on which it's placed goes up or down, respec Tively.
By choosing her weighings carefully, Sally was able to ensure that she'll find the counterfeit coin with exactly three we Ighings.

Input

The first line of input is a integer n (n > 0) specifying the number of cases to follow. Each case consists of three lines of input, one for each weighing. Sally has identified each of the coins with the letters A--L. Information on A weighing would be given by both strings of Le Tters and then one of the words "up", "down", or "even". The first string of letters would represent the coins on the left balance; The second string, the coins on the right balance. (Sally'll always place the same number of coins in the right balance as on the left balance.) The word in the third position would tell whether the right side of the balance goes up, down, or remains even.

Output

For each case, the output would identify the counterfeit coin by their letter and tell whether it's heavy or light. The solution is always uniquely determined.

Sample Input

Sample Output

K is the counterfeit coin and it's light.

Test instructions is a dollar from a to L, and one of them is different from the others, which may be light or heavy. Give three of the relationship on the scale, you have to determine which one is forged dollar, is light is heavy.

Do when also wa a few times, but after AC feel this question is really water ah ... I do not know why, as long as the end of a very hard to think that the problem is really water, why did not think of it? That's the feeling.

Cough, because the problem is a to L, the amount of data is too small, resulting in enumeration is OK. So start from a a try it, if in the even in the statement appeared, then ruled out its suspicion. Appears in the UP statement, its flag plus 3, which represents a possible light tag. Appears in the down statement, its own flag plus 4, which represents a potentially heavy mark.

Then after the 12 weights marked, there is the exclusion marked 1, labeled 7 10 11 Such an exclusion, because it is not possible to have a weight is light and heavy situation, and then find the most unique one is a forged weight. Output can be.

Code:

#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string > #include <cstring> #include <map>using namespace Std;int num[15];int test,i,j,flag[15],sum=0;string Left_s[5],right_s[5],bala[5];char temp_c;void Solve () {if (bala[1]== "up") {for (J=0;j<left_s[1].length (); j + +) {if ( Left_s[1][j]==temp_c) {sum=1;cout<<temp_c<< "is the counterfeit coin and it is";cout<< "heavy." <<endl;return;}} For (J=0;j<right_s[1].length (); j + +) {if (Right_s[1][j]==temp_c) {sum=1;cout<<temp_c<< "is the Counterfeit coin and it is the ";cout<<" light. " <<endl;return;}}} if (bala[2]== "up") {for (J=0;j<left_s[2].length (); j + +) {if (Left_s[2][j]==temp_c) {sum=1;cout<<temp_c< < "is the counterfeit coin and it is";cout<< "heavy." <<endl;return;}} For (J=0;j<right_s[2].length (); j + +) {if (Right_s[2][j]==temp_c) {sum=1;cout<<temp_c<< "is the Counterfeit coin and it is the ";cout<<" light. "<<endl;return;}}} if (bala[3]== "up") {for (J=0;j<left_s[3].length (); j + +) {if (Left_s[3][j]==temp_c) {sum=1;cout<<temp_c< < "is the counterfeit coin and it is";cout<< "heavy." <<endl;return;}} For (J=0;j<right_s[3].length (); j + +) {if (Right_s[3][j]==temp_c) {sum=1;cout<<temp_c<< "is the Counterfeit coin and it is the ";cout<<" light. " <<endl;return;}}} if (bala[1]== "down") {for (J=0;j<left_s[1].length (); j + +) {if (Left_s[1][j]==temp_c) {sum=1;cout<<temp_c< < "is the counterfeit coin and it's";cout<< "light." <<endl;return;}} For (J=0;j<right_s[1].length (); j + +) {if (Right_s[1][j]==temp_c) {sum=1;cout<<temp_c<< "is the Counterfeit coin and it is ";cout<<" heavy. " <<endl;return;}}} if (bala[2]== "down") {for (J=0;j<left_s[2].length (); j + +) {if (Left_s[2][j]==temp_c) {sum=1;cout<<temp_c< < "is the counterfeit coin and it's";cout<< "light." <<endl;return;}} For (J=0;j<right_s[2].length (); j + +) {if(Right_s[2][j]==temp_c) {sum=1;cout<<temp_c<< "is the counterfeit coin and it is";cout<< "heavy." <<endl;return;}}} if (bala[3]== "down") {for (J=0;j<left_s[3].length (); j + +) {if (Left_s[3][j]==temp_c) {sum=1;cout<<temp_c< < "is the counterfeit coin and it's";cout<< "light." <<endl;return;}} For (J=0;j<right_s[3].length (); j + +) {if (Right_s[3][j]==temp_c) {sum=1;cout<<temp_c<< "is the Counterfeit coin and it is ";cout<<" heavy. " <<endl;return;}}}} BOOL Pend () {int pend_flag=0;if (bala[1]== "up") {for (J=0;j<left_s[1].length (); j + +) {if (Left_s[1][j]==temp_c) {Pend _flag=1;}} For (J=0;j<right_s[1].length (); j + +) {if (right_s[1][j]==temp_c) {pend_flag=1;}} if (pend_flag==0) return false;} if (bala[2]== "up") {for (J=0;j<left_s[2].length (); j + +) {if (left_s[2][j]==temp_c) {pend_flag=1;}} For (J=0;j<right_s[2].length (); j + +) {if (right_s[2][j]==temp_c) {pend_flag=1;}} if (pend_flag==0) return false;} if (bala[3]== "up") {for (J=0;j<left_s[3].length (); j + +) {if(Left_s[3][j]==temp_c) {pend_flag=1;}} For (J=0;j<right_s[3].length (); j + +) {if (right_s[3][j]==temp_c) {pend_flag=1;}} if (pend_flag==0) return false;} if (bala[1]== "down") {for (J=0;j<left_s[1].length (); j + +) {if (left_s[1][j]==temp_c) {pend_flag=1;}} For (J=0;j<right_s[1].length (); j + +) {if (right_s[1][j]==temp_c) {pend_flag=1;}} if (pend_flag==0) return false;} if (bala[2]== "down") {for (J=0;j<left_s[2].length (); j + +) {if (left_s[2][j]==temp_c) {pend_flag=1;}} For (J=0;j<right_s[2].length (); j + +) {if (right_s[2][j]==temp_c) {pend_flag=1;}} if (pend_flag==0) return false;} if (bala[3]== "down") {for (J=0;j<left_s[3].length (); j + +) {if (left_s[3][j]==temp_c) {pend_flag=1;}} For (J=0;j<right_s[3].length (); j + +) {if (right_s[3][j]==temp_c) {pend_flag=1;}} if (pend_flag==0) return false;} return true;} int main () {cin>>test;while (test--) {memset (flag,0,sizeof (flag)); memset (num,0,sizeof (num)); Sum=0;for (i=1;i <=3;i++) {cin>>left_s[i]>>right_s[i]>>bala[i];} for (temp_c= ' A '; temp_c<= ' L '; temp_c++) {if (bala[1]== "Even ") {for (J=0;j<left_s[1].length (); j + +) {if (left_s[1][j]==temp_c) {flag[temp_c-' A ']=1;break;}} For (J=0;j<right_s[1].length (); j + +) {if (right_s[1][j]==temp_c) {flag[temp_c-' A ']=1;break;}}} if (bala[2]== "even") {for (J=0;j<left_s[2].length (); j + +) {if (left_s[2][j]==temp_c) {flag[temp_c-' A ']=1;break;}} For (J=0;j<right_s[2].length (); j + +) {if (right_s[2][j]==temp_c) {flag[temp_c-' A ']=1;break;}}} if (bala[3]== "even") {for (J=0;j<left_s[3].length (); j + +) {if (left_s[3][j]==temp_c) {flag[temp_c-' A ']=1;break;}} For (J=0;j<right_s[3].length (); j + +) {if (right_s[3][j]==temp_c) {flag[temp_c-' A ']=1;break;}}} if (bala[1]== "up") {for (J=0;j<left_s[1].length (); j + +) {if (Left_s[1][j]==temp_c) {if (flag[temp_c-' A ']==1) continue;elseflag[temp_c-' A '] + = 4;}} For (J=0;j<right_s[1].length (); j + +) {if (Right_s[1][j]==temp_c) {if (flag[temp_c-' A ']==1) continue;elseflag[temp_ C ' A '] + = 3;}} if (bala[2]== "up") {for (J=0;j<left_s[2].length (); j + +) {if (Left_s[2][j]==temp_c) {if (flag[temp_c-' A ']==1) continue;elseflag[temp_c-' A '] + = 4;}} For (j=0;j<right_s[2].length (); j + +) {if (Right_s[2][j]==temp_c) {if (flag[temp_c-' a ']==1) continue;elseflag[temp_c-' a ' ] + = 3;}} if (bala[3]== "up") {for (J=0;j<left_s[3].length (); j + +) {if (Left_s[3][j]==temp_c) {if (flag[temp_c-' A ']==1) continue;elseflag[temp_c-' A '] +=4;}} For (J=0;j<right_s[3].length (); j + +) {if (Right_s[3][j]==temp_c) {if (flag[temp_c-' A ']==1) continue;elseflag[temp_ C ' A '] +=3;}}} if (bala[1]== "down") {for (J=0;j<left_s[1].length (); j + +) {if (Left_s[1][j]==temp_c) {if (flag[temp_c-' A ']==1) continue;elseflag[temp_c-' A '] +=3;}} For (J=0;j<right_s[1].length (); j + +) {if (Right_s[1][j]==temp_c) {if (flag[temp_c-' A ']==1) continue;elseflag[temp_ C ' A '] +=4;}}} if (bala[2]== "down") {for (J=0;j<left_s[2].length (); j + +) {if (Left_s[2][j]==temp_c) {if (flag[temp_c-' A ']==1) continue;elseflag[temp_c-' A '] +=3;}} For (J=0;j<right_s[2].length (); j + +) {if (Right_s[2][j]==temp_c) {if (flag[temp_c-' A ']==1) continue;elseflag[temp_ C ' A '] +=4;}}} if (bala[3]== "down") {for (J=0;j<left_s[3].length (); j + +) {if (Left_s[3][j]==temp_c) {if (flag[temp_c-' a ']==1) continue;elseflag[temp_c-' a '] +=3;}} For (J=0;j<right_s[3].length (); j + +) {if (Right_s[3][j]==temp_c) {if (flag[temp_c-' A ']==1) continue;elseflag[temp_ C ' A '] +=4;}}}        For (temp_c= ' a '; temp_c<= ' L '; temp_c++) {num[flag[temp_c-' a ']]++;} for (i=0;i<=12;i++) {if (num[i]==1 && i!=7 && i!=10 && i!=11) {for (temp_c= ' A '; temp_c<= ' L '; temp_c++) {if (flag[temp_c-' A ']==i) {if (Pend ()) {Solve ();}}}}} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 1013:counterfeit Dollar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.