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

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. 
题目大意:有12枚硬币,里面有一个是假的,称三次,判断哪枚是假的,并且判断假的比真的轻还是重。
解题方法:直接枚举,总共有24中情况,即每一枚硬币都有可能比真的轻或者重,枚举这24种情况,即可得出答案。
#include <stdio.h>
#include <string.h> int main()
{
char str1[], str2[], balance[];
int nCase, ans[];//ans用于记录每种情况满足的次数有多少次
scanf("%d", &nCase);
while(nCase--)
{
memset(ans, , sizeof(ans));
for (int i = ; i < ; i++)
{
scanf("%s%s%s", str1, str2, balance);
//j等于0到11依次表示A-L中假币轻,j等于12到23依次表示A-L中假币重
for (int j = ; j < ; j++)
{
switch(balance[])
{
case 'e':
{
bool flag = true;
//如果假币轻则在两边都应该找不到该硬币
if (j < )
{
for (int k = ; k < strlen(str1); k++)
{
if (str1[k] == 'A' + j)
{
flag = false;
}
}
for (int k = ; k < strlen(str2); k++)
{
if (str2[k] == 'A' + j)
{
flag = false;
}
}
}
//如果假币重则在两边都应该找不到该硬币
else
{
for (int k = ; k < strlen(str1); k++)
{
if (str1[k] == 'A' + j - )
{
flag = false;
}
}
for (int k = ; k < strlen(str2); k++)
{
if (str2[k] == 'A' + j - )
{
flag = false;
}
}
}
//如果两边都没找到,则说明满足条件
if (flag)
{
ans[j]++;
}
}
break;
case 'u':
{
bool flag = false;
//如果左边重则轻的假币放在右边
if (j < )
{
for (int k = ; k < strlen(str2); k++)
{
if (str2[k] == 'A' + j)
{
flag = true;
}
}
}
//如果左边重则重的假币放在左边
else
{
for (int k = ; k < strlen(str1); k++)
{
if (str1[k] == 'A' + j - )
{
flag = true;
}
}
}
if (flag)
{
ans[j]++;
}
}
break;
case 'd':
{
bool flag = false;
//如果右边重,则轻的假币放在左边
if (j < )
{
for (int k = ; k < strlen(str1); k++)
{
if (str1[k] == 'A' + j)
{
flag = true;
}
}
}
//如果右边重,则重的假币放在右边
else
{
for (int k = ; k < strlen(str2); k++)
{
if (str2[k] == 'A' + j - )
{
flag = true;
}
}
}
if (flag)
{
ans[j]++;
}
}
break;
}
}
}
for (int i = ; i < ; i++)
{
//ans[i] == 3说明这种情况满足三次称量的结果
if (ans[i] == )
{
//假币比真币轻
if (i < )
{
printf("%c is the counterfeit coin and it is light.\n", i + 'A');
}
//假币比真币重
else
{
printf("%c is the counterfeit coin and it is heavy.\n", i - + 'A');
}
break;
}
}
}
return ;
}

POJ 1013 Counterfeit Dollar的更多相关文章

  1. Poj 1013 Counterfeit Dollar / OpenJudge 1013(2692) 假币问题

    1.链接地址: http://poj.org/problem?id=1013 http://bailian.openjudge.cn/practice/2692 http://bailian.open ...

  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 分类: POJ 2015-06-12 15:28 19人阅读 评论(0) 收藏

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

  6. POJ1013 Counterfeit Dollar

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

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

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

  8. poj1013.Counterfeit Dollar(枚举)

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

  9. POJ 1013 小水题 暴力模拟

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

随机推荐

  1. jenkins2 pipeline实例

    比较完整的实例,使用了maven打包,git tag,发通知邮件,等待用户deploy,deploy到nexus. 文章来自:http://www.ciandcd.com文中的代码来自可以从githu ...

  2. Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. 试图加载格式不正确的程序。

    出现上述问题的原因是,所加载的程序集中有32位的,也有64位的,IIS 7 程序池 在Windows下.Net FrameWork是64位的,要想正确使用,需要对程序池进行配置.如下图所示:

  3. netstat常见参数

    -a (all)显示所有选项,默认不显示LISTEN相关-t (tcp)仅显示tcp相关选项-u (udp)仅显示udp相关选项-n 拒绝显示别名,能显示数字的全部转化成数字.-l 仅列出有在 Lis ...

  4. js脚本语言基础和数组

    js和PHP中,字符串赋值:要使用"双引号"或"单引号"引起来:例如:var c="你好"不同类型进行数学运算,要转换,类型转换:强制转换p ...

  5. EndPoint详解

    EndPoint详解 EndPoint主要用于暴露一些SpringMvc内部运行的信息,通常是通过SpringMvc的请求地址获取相关信息.如/health获取健康检查信息. 简单单元测试 @Test ...

  6. node.js在windows环境下的安装

    node.js官网 https://nodejs.org/en/ Download

  7. [原创]配置管理技术圈QQ群:129489184

    [原创]配置管理技术圈QQ群:129489184 配置管理技术圈QQ群:129489184,研究cvs,svn,git,cc等平台配置技术,涉及版本控制,持续集成,自动化构建等! 欢迎各位同学来,来时 ...

  8. Cocos2d-x3.x塔防游戏(保卫萝卜)从零开始(二)

    一.前提: 完成前一篇的内容. 具体参考:Cocos2d-x3.x塔防游戏(保卫萝卜)从零开始(一)篇 二.本篇目标: l  说说关于cocos2dx手机分辨率适配 l  对前一篇完成的塔防游戏原型进 ...

  9. Android——GridView(网格视图)相关知识总结贴

    Android API中文文档GridView http://www.apkbus.com/android-14131-1-1.html   Android API 中文 (15) —— GridVi ...

  10. Zabbix监控Windows事件日志

    1.zabbix_agentd.win文件修改: LogFile=c:\zabbix\zabbix_agentd.log Server=1.16.2.4 ServerActive=1.16.2.4 H ...