zoukankan      html  css  js  c++  java
  • Poj 1013 Counterfeit Dollar / OpenJudge 1013(2692) 假币问题

    1.链接地址:

    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

    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 }
  • 相关阅读:
    【Codeforces】Codeforces Round #680 Div2
    PS1 长命令回到行首进行覆盖
    vue 跟路径加载缺少跟前缀
    Mac OS Virtualbox 倒入 ova 镜像文件
    笔记本电脑扩展屏幕或设备后不能播放声音
    git clone 后使用子分支
    laravel 环境自编译过程
    virtual Box centos7 公司网络环境下不能联网的解决方案
    CentOS7 php7 安装 curl 扩展
    CentOS 7 安装 Nodejs npm 及版本冲突解决
  • 原文地址:https://www.cnblogs.com/mobileliker/p/3546623.html
Copyright © 2011-2022 走看看