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. [游戏模版5] Win32 折线 弧线

    >_<:first build some points put in poly1[],poly2[] and poly3[] in the function of InitInstance ...

  2. iOS YSMine 通用设置

    概述 我们在开发的过程中,经常需要重复的写个人中心设置的代码,很多情况下,我们都是通过if(indexPath.row)来判断操作以及要跳转的页面,这样的情况是非常不友好的,尤其是当我们需要调整显示顺 ...

  3. paip.-Djava.library.path -Djava.ext.dirs= 的区别

    paip.-Djava.library.path  -Djava.ext.dirs= 的区别 作者Attilax  艾龙,  EMAIL:1466519819@qq.com  来源:attilax的专 ...

  4. atitit.提升备份文件复制速度(1) -----分析统计问题and解决方案

    atitit.) -----分析统计问题and解决方案 1. 现在的情形 1 2. 硬盘信息 大概50mb/s, 50iops 1 3. 统计小的文件比率 2 4. 复制速度估计.. 2 5. 小文件 ...

  5. "Cannot find one of more components. Please reinstall the application"--安装VS2013之后不能正常打开的处理办法

    今天,安装完VS2013之后,不能正常启动.总提示一个让人摸不到头脑的错误: "Cannot find one of more components. Please reinstall th ...

  6. VC中打开对话框选择文件和文件夹

    1.选择文件               CFileDialogdlg(true, NULL, NULL, NULL, "所有文件 | *.*", this);           ...

  7. Android ImageView圆形头像

    转载自:http://m.oschina.net/blog/321024 Android ImageView圆形头像 图片完全解析 我们在做项目的时候会用到圆形的图片,比如用户头像,类似QQ.用户在用 ...

  8. 谈一谈PHP的代码重构

    随着 PHP 从一种简单的脚本语言转变为一种成熟的编程语言,一个典型的 PHP 应用程序的代码库的复杂性也随之增大.为了控制对这些应用程序的支持和维护,我们可以使用各种测试工具来自动化该流程.其中一种 ...

  9. APK重签名总结

    keytool -genkey -alias aeo_android.keystore -keyalg RSA -validity 20000 -keystore aeo_android.keysto ...

  10. sublime3 配置node build环境

    折腾了很久,原来如此简单 1.package control  安装nodejs 2.修改Nodejs.sublime-settings文件,将nodejs路径修改成自己的 3.sublime tex ...