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.代码:

 #include <iostream>
#include <cstdio>
#include <string> using namespace std; int main()
{
string str_left[];
string str_right[];
string str_res[]; int n;
cin>>n; int i,j,k; while(n--)
{
for(i = ; i < ; ++i) cin>>str_left[i]>>str_right[i]>>str_res[i];
for(i = ; i < ; ++i)
{
for(j = ; j < ; ++j)
{
for(k = ; k < ; ++k)
{
char ch = 'A' + i;
string::size_type idx_left = str_left[k].find(ch);
string::size_type idx_right = str_right[k].find(ch); if(idx_left != string::npos)
{
if(j == ) //heavy
{
if(str_res[k] != "up") break;
}
else
{
if(str_res[k] != "down") break;
}
}
else if(idx_right != string::npos)
{
if(j == )
{
if(str_res[k] != "down") break;
}
else
{
if(str_res[k] != "up") break;
}
}
else
{
if(str_res[k] != "even") break;
} }
if(k >= ) break;
}
if(j < ) break;
}
if(j == ) cout<<(char)('A' + i)<<" is the counterfeit coin and it is heavy."<<endl;
else cout<<(char)('A' + i)<<" is the counterfeit coin and it is light."<<endl;
}
return ;
}

Poj 1013 Counterfeit Dollar / OpenJudge 1013(2692) 假币问题的更多相关文章

  1. POJ 1013 Counterfeit Dollar

    Counterfeit Dollar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36206   Accepted: 11 ...

  2. POJ 1013 Counterfeit Dollar 集合上的位运算

    Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are t ...

  3. 思维+模拟--POJ 1013 Counterfeit Dollar

    Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver d ...

  4. POJ 1013:Counterfeit Dollar

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

  5. Counterfeit Dollar -----判断12枚钱币中的一个假币

     Counterfeit Dollar Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u ...

  6. Counterfeit Dollar 分类: POJ 2015-06-12 15:28 19人阅读 评论(0) 收藏

    Counterfeit Dollar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 41559   Accepted: 13 ...

  7. POJ1013 Counterfeit Dollar

    题目来源:http://poj.org/problem?id=1013 题目大意:有12枚硬币,其中有一枚假币.所有钱币的外表都一样,所有真币的重量都一样,假币的重量与真币不同,但我们不知道假币的重量 ...

  8. poj1013.Counterfeit Dollar(枚举)

    Counterfeit Dollar Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 415  Solved: 237 Description Sally ...

  9. 模拟,找次品硬币,Counterfeit Dollar(POJ 1013)

    题目链接:http://poj.org/problem?id=1013 解题报告: 1.由于次品的重量不清楚,用time['L'+1]来记录各个字母被怀疑的次数.为负数则轻,为正数则重. 2.用zer ...

随机推荐

  1. XMIND

    XMind 是一款非常实用的商业思维导图软件,应用全球最先进的Eclipse RCP 软件架构,全力打造易用.高效的可视化思维软件,强调软件的可扩展.跨平台.稳定性和性能,致力于使用先进的软件技术帮助 ...

  2. Ps切图学习

    1.切图的原文件格式为psd,用ps工具打开 2.鼠标点击需要切的图片,会自动选中图层: 3.选择需要切图的图层,右键复制图层 宽高必须为2的倍数 文件-存储为web和设备所用格式 预设选择为png- ...

  3. Parameterized Path 的例子

    Improve the planner's ability to use nested loops with inner index scans (Tom Lane) The new "pa ...

  4. 【55】让自己熟悉Boost

    1.网址:http://boost.org 2.有很多C++组织和网站,但是Boost库有两个优势:a.和标准委员会关系密切:b.加入C++标准的各种功能的测试场.

  5. Codeforces Round #200 (Div. 1) B. Alternating Current 栈

    B. Alternating Current Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...

  6. cocos2d-x读取xml(适用于cocos2d-x 2.0以上版本号)

    为了能在cocos2d-x的文本标签中显示中文,一个是转换文件编码格式,还有一种就是读取utf-8格式的xml文件.我选择了后者,其原因大家可以去搜索一下cocos2d-x显示中文,希望可以你给答案. ...

  7. 飘逸的python - 使用dis模块进行代码层次的性能剖析

    http://blog.csdn.net/handsomekang/article/details/41479597?utm_source=tuicool&utm_medium=referra ...

  8. C#_dropdownlist_2

    string deptId =Request.Form["depts"].Trim(); Html.DropDownList()赋默认值: 页面代码如下: <%        ...

  9. Overview & Change Log

    Overview & Change Log Nova Framework is a PHP 5.5+ MVC Framework. It's designed to be lightweigh ...

  10. iOS常见文件及程序的启动原理

    一. iOS中常见文件 (一). Xcode6之前 创建项目,默认可以看见一个存放框架的文件夹 info文件以工程文件名开头,如:第一个项目-Info.plist 项目中默认有一个PCH文件 (二). ...