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. MySQL中UNION和UNION ALL的使用

    在数据库中,UNION和UNION ALL关键字都是将两个结果集合并为一个,但这两者从使用和效率上来说都有所不同. MySQL中的UNION UNION在进行表链接后会筛选掉重复的记录,所以在表链接后 ...

  2. tableview 上拉时 标题行出现在顶部不动效果

    类似这种效果: 其实很简单,利用tableview 的plain属性,然后使用section,其实滑上去不动的是  section的headView. -(NSInteger)numberOfSect ...

  3. Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心

    C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...

  4. WCF之初体验

    什么是WCF? WCF的全称是:Windows通信基础(WindowsCommunication Foundation).本质来讲,他是一套软件开发包. WCF和WebService的差别 Webse ...

  5. 关于js的replace替换

    关于js的replace替换 msgContent = msgContent.replace("a","b"); 这样的替换只会把第一个a替换成b,不会替换全部 ...

  6. 升级ADT22.6后,Android模拟器无法创建

    这 两天,在社区里看到有小伙伴们反应,自己在Eclipse下无法创建Android模拟器的问题.起初,自己也没太在意,我一直使用的是 Genymotion模拟器.然后,问题不解决,总有那么一天会让自己 ...

  7. JavaScript(20)jQuery HTML 加入和删除元素

    jQuery - 加入元素 通过 jQuery,能够非常easy地加入新元素/内容. 加入新的 HTML 内容的四个 jQuery 方法: append() - 在被选元素的结尾插入内容 prepen ...

  8. java_泛型,设置类型通配符的上限

    package ming; import java.util.ArrayList; import java.util.Collection; import java.util.List; class ...

  9. java跨平台性分析

    实不相瞒,Java是我见过的执行效率最低的程序设计语言,前不久在CSDN论坛上有个评测,计算9999的阶乘,同样的循环算法,Java的耗时是.NET的5倍.我以前很喜欢Serv-U,自从它用Java重 ...

  10. windows 7文件共享方法

    现在家里有几台电脑是很常见的,把家里的几台电脑组成局域网,共享文件.联机游戏是非常有必要的,但是组建局域网又是很多朋友永远的痛,需要设置工作组.设置登录方式.打开服务等等,时常还会出点小问题而无法共享 ...