Poj 1013 simulated question coin weighing

Source: Internet
Author: User

Poj 1013

 

Counterfeit dollar
Time limit:1000 ms   Memory limit:10000 K
Total submissions:27117   Accepted:8460

Description

Sally Jones has a dozen Voyageur silver dollars. however, only eleven of the coins are true silver dollars; one coin is counterfeit even though its color and size make it indistinguishable from the real silver dollars. the counterfeit coin has a different weight from the other coins but Sally does not know if it is heavier or lighter than the real coins.
Happily, Sally has a friend who loans her a very accurate balance scale. the friend will permit Sally three weighings to find the counterfeit coin. for instance, if Sally weighs two coins against each other and the scales balance then she knows these two coins are 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 is counterfeit and she can tell whether it is light or heavy depending on whether the balance on which it is placed goes up or down, respectively.
By choosing her weighings carefully, Sally is able to ensure that she will find the counterfeit coin with exactly three weighings.

Input

The first line of input is an 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 will be given by two strings of letters and then one of the words ''up '', ''down'', or ''even ''. the first string of letters will represent the coins on the left balance; the second string, the coins on the right balance. (Sally will always place the same number of coins on the right balance as on the left balance .) the word in the third position will tell whether the right side of the balance goes up, down, or remains even.

Output

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.

Sample Input

1 ABCD EFGH even ABCI EFJK up ABIJ EFGH even 

Sample output

K is the counterfeit coin and it is light. 

Source

East central North America 1998

 

AC code

// Typical simulated questions <br/> // the key idea is to imagine the results in 24 cases where the coin is heavy or light, one-to-one comparison <br/> // here we first assume that the coin is too heavy, 0 indicates not in, and 1 indicates on the left, -1 indicates <br/> // when the coin is light on the right, it is exactly the opposite of the expected situation <br/> # include <iostream> <br/> # include <string> <br/> # include <fstream> <br/> # include <memory. h> <br/> using namespace STD; <br/> int main () {<br/> int exp [12] [3]; <br/> int result [3]; <br/> int N, I, j; <br/> string S1, S2, S3; <br/> CIN> N; <br/> while (n --) {<br/> memset (exp, 0, sizeof (exp )); <br/> memset (result, 0, sizeof (result); <br/> // The following three experiments are started, simulate the result <br/> for (I = 0; I <3; I ++) <br/>{< br/> CIN> S1> S2> S3; <br/> for (j = 0; j <s1.size (); j ++) <br/> {<br/> exp [S1 [J]-'a'] [I] = 1; // indicates that the coin is on the left <br/> exp [S2 [J]-'a'] [I] =-1; // indicates that the coin is on the right <br/>}< br/> If (S3 = "even ") <br/> {<br/> result [I] = 0; // indicates that the coin is not on the balance at this time <br/>}< br/> else if (S3 = "down ") <br/> {<br/> result [I] =-1; // indicates that at this time, the coin should appear on the Right To <br/>}< br/> else result [I] = 1; <br/>}</P> <p> for (j = 0; j <12; j ++) <br/> {<br/> If (exp [J] [0] = Result [0] & exp [J] [1] = Result [1] & & exp [J] [2] = Result [2]) <br/> {<br/> cout <char ('A' + J) <"is the counterfeit coin and it is heavy. "<Endl; <br/> break; <br/>}< br/> else if (exp [J] [0] =-result [0] & exp [J] [1] =-result [1] & exp [J] [2] =-result [2]) <br/> {<br/> cout <char ('A' + J) <"is the counterfeit coin and it is light. "<Endl; <br/> break; <br/>}< br/> return 0; <br/>}< br/> 

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.