Poj 1013 Counterfeit Dollar/OpenJudge 1013(2692)위 폐 문제
12901 단어 count
http://poj.org/problem?id=1013
http://bailian.openjudge.cn/practice/2692
http://bailian.openjudge.cn/practice/1013
2.제목:
Counterfeit Dollar
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 37454
Accepted: 11980
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
3.사고방식:
매 거 법,모든 상황 을 매 거 하면 된다.
4.코드:
1 #include <iostream>
2 #include <cstdio>
3 #include <string>
4
5 using namespace std;
6
7 int main()
8 {
9 string str_left[3];
10 string str_right[3];
11 string str_res[3];
12
13 int n;
14 cin>>n;
15
16 int i,j,k;
17
18 while(n--)
19 {
20 for(i = 0; i < 3; ++i) cin>>str_left[i]>>str_right[i]>>str_res[i];
21 for(i = 0; i < 12; ++i)
22 {
23 for(j = 0; j < 2; ++j)
24 {
25 for(k = 0; k < 3; ++k)
26 {
27 char ch = 'A' + i;
28 string::size_type idx_left = str_left[k].find(ch);
29 string::size_type idx_right = str_right[k].find(ch);
30
31 if(idx_left != string::npos)
32 {
33 if(j == 0) //heavy
34 {
35 if(str_res[k] != "up") break;
36 }
37 else
38 {
39 if(str_res[k] != "down") break;
40 }
41 }
42 else if(idx_right != string::npos)
43 {
44 if(j == 0)
45 {
46 if(str_res[k] != "down") break;
47 }
48 else
49 {
50 if(str_res[k] != "up") break;
51 }
52 }
53 else
54 {
55 if(str_res[k] != "even") break;
56 }
57
58 }
59 if(k >= 3) break;
60 }
61 if(j < 2) break;
62 }
63 if(j == 0) cout<<(char)('A' + i)<<" is the counterfeit coin and it is heavy."<<endl;
64 else cout<<(char)('A' + i)<<" is the counterfeit coin and it is light."<<endl;
65 }
66 return 0;
67 }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[react] 간단한 카운터앱 만들기스파르타 코딩클럽 앱개발플러스 1주차 수강을 마무리하는 날, 매주마다 숙제로 마무리를 하는데, 난 거의 숙제해설을 보고 하는 편... ㅎㅎ;; 뭐 ㅋ도 모르면서 코딩을 하다보니... 그래도 종합반을 듣고 와서 그런지...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.