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

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.

题意是从A到L的dollar,其中有一个跟他们其它的不同,可能是轻了也可能是重了。给了三个在秤上的关系,要你判断出哪一个是伪造的dollar,是轻是重。

做的时候还WA了几次,但AC之后觉得这个题真是水啊。。。不知道为什么只要自己好不容易A完之后就觉得这个题真的很水,为什么当时没有想到呢?就是这种感觉。

咳咳,因为这个题就A到L之中有问题嘛,数据量太小,导致枚举就OK了。所以从A开始就一个一个试吧,如果在even中的语句里出现了,那就排除它的嫌疑。在up语句中出现了,它的flag加3,代表可能是轻的标记。在down语句中出现了,它自己的flag加4,代表可能是重的标记。

然后对12个砝码标记完之后,有标记为1的排除,标记为7 10 11这样的排除,因为不可能出现一个砝码既轻又重的情况,然后找最独特的那一个就是伪造的砝码了。输出即可。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
using namespace std; int num[15];
int Test,i,j,flag[15],sum=0;
string left_s[5],right_s[5],bala[5];
char temp_c; void solve()
{
if(bala[1]=="up")
{
for(j=0;j<left_s[1].length();j++)
{
if(left_s[1][j]==temp_c)
{
sum=1;
cout<<temp_c<<" is the counterfeit coin and it is ";
cout<<"heavy."<<endl;
return ;
}
}
for(j=0;j<right_s[1].length();j++)
{
if(right_s[1][j]==temp_c)
{
sum=1;
cout<<temp_c<<" is the counterfeit coin and it is ";
cout<<"light."<<endl;
return;
}
}
}
if(bala[2]=="up")
{
for(j=0;j<left_s[2].length();j++)
{
if(left_s[2][j]==temp_c)
{
sum=1;
cout<<temp_c<<" is the counterfeit coin and it is ";
cout<<"heavy."<<endl;
return;
}
}
for(j=0;j<right_s[2].length();j++)
{
if(right_s[2][j]==temp_c)
{
sum=1;
cout<<temp_c<<" is the counterfeit coin and it is ";
cout<<"light."<<endl;
return;
}
}
}
if(bala[3]=="up")
{
for(j=0;j<left_s[3].length();j++)
{
if(left_s[3][j]==temp_c)
{
sum=1;
cout<<temp_c<<" is the counterfeit coin and it is ";
cout<<"heavy."<<endl;
return ;
}
}
for(j=0;j<right_s[3].length();j++)
{
if(right_s[3][j]==temp_c)
{
sum=1;
cout<<temp_c<<" is the counterfeit coin and it is ";
cout<<"light."<<endl;
return ;
}
}
} if(bala[1]=="down")
{
for(j=0;j<left_s[1].length();j++)
{
if(left_s[1][j]==temp_c)
{
sum=1;
cout<<temp_c<<" is the counterfeit coin and it is ";
cout<<"light."<<endl;
return;
}
}
for(j=0;j<right_s[1].length();j++)
{
if(right_s[1][j]==temp_c)
{
sum=1;
cout<<temp_c<<" is the counterfeit coin and it is ";
cout<<"heavy."<<endl;
return ;
}
}
}
if(bala[2]=="down")
{
for(j=0;j<left_s[2].length();j++)
{
if(left_s[2][j]==temp_c)
{
sum=1;
cout<<temp_c<<" is the counterfeit coin and it is ";
cout<<"light."<<endl;
return;
}
}
for(j=0;j<right_s[2].length();j++)
{
if(right_s[2][j]==temp_c)
{
sum=1;
cout<<temp_c<<" is the counterfeit coin and it is ";
cout<<"heavy."<<endl;
return ;
}
}
}
if(bala[3]=="down")
{
for(j=0;j<left_s[3].length();j++)
{
if(left_s[3][j]==temp_c)
{
sum=1;
cout<<temp_c<<" is the counterfeit coin and it is ";
cout<<"light."<<endl;
return;
}
}
for(j=0;j<right_s[3].length();j++)
{
if(right_s[3][j]==temp_c)
{
sum=1;
cout<<temp_c<<" is the counterfeit coin and it is ";
cout<<"heavy."<<endl;
return ;
}
}
}
} bool pend()
{
int pend_flag=0;
if(bala[1]=="up")
{
for(j=0;j<left_s[1].length();j++)
{
if(left_s[1][j]==temp_c)
{
pend_flag=1;
}
}
for(j=0;j<right_s[1].length();j++)
{
if(right_s[1][j]==temp_c)
{
pend_flag=1;
}
}
if(pend_flag==0)
return false;
}
if(bala[2]=="up")
{
for(j=0;j<left_s[2].length();j++)
{
if(left_s[2][j]==temp_c)
{
pend_flag=1;
}
}
for(j=0;j<right_s[2].length();j++)
{
if(right_s[2][j]==temp_c)
{
pend_flag=1;
}
}
if(pend_flag==0)
return false;
}
if(bala[3]=="up")
{
for(j=0;j<left_s[3].length();j++)
{
if(left_s[3][j]==temp_c)
{
pend_flag=1;
}
}
for(j=0;j<right_s[3].length();j++)
{
if(right_s[3][j]==temp_c)
{
pend_flag=1;
}
}
if(pend_flag==0)
return false;
} if(bala[1]=="down")
{
for(j=0;j<left_s[1].length();j++)
{
if(left_s[1][j]==temp_c)
{
pend_flag=1;
}
}
for(j=0;j<right_s[1].length();j++)
{
if(right_s[1][j]==temp_c)
{
pend_flag=1;
}
}
if(pend_flag==0)
return false;
}
if(bala[2]=="down")
{
for(j=0;j<left_s[2].length();j++)
{
if(left_s[2][j]==temp_c)
{
pend_flag=1;
}
}
for(j=0;j<right_s[2].length();j++)
{
if(right_s[2][j]==temp_c)
{
pend_flag=1;
}
}
if(pend_flag==0)
return false;
}
if(bala[3]=="down")
{
for(j=0;j<left_s[3].length();j++)
{
if(left_s[3][j]==temp_c)
{
pend_flag=1;
}
}
for(j=0;j<right_s[3].length();j++)
{
if(right_s[3][j]==temp_c)
{
pend_flag=1;
}
}
if(pend_flag==0)
return false;
}
return true;
}
int main()
{
cin>>Test; while(Test--)
{
memset(flag,0,sizeof(flag));
memset(num,0,sizeof(num));
sum=0; for(i=1;i<=3;i++)
{
cin>>left_s[i]>>right_s[i]>>bala[i];
}
for(temp_c='A';temp_c<='L';temp_c++)
{
if(bala[1]=="even")
{
for(j=0;j<left_s[1].length();j++)
{
if(left_s[1][j]==temp_c)
{
flag[temp_c-'A']=1;
break;
}
}
for(j=0;j<right_s[1].length();j++)
{
if(right_s[1][j]==temp_c)
{
flag[temp_c-'A']=1;
break;
}
}
}
if(bala[2]=="even")
{
for(j=0;j<left_s[2].length();j++)
{
if(left_s[2][j]==temp_c)
{
flag[temp_c-'A']=1;
break;
}
}
for(j=0;j<right_s[2].length();j++)
{
if(right_s[2][j]==temp_c)
{
flag[temp_c-'A']=1;
break;
}
}
}
if(bala[3]=="even")
{
for(j=0;j<left_s[3].length();j++)
{
if(left_s[3][j]==temp_c)
{
flag[temp_c-'A']=1;
break;
}
}
for(j=0;j<right_s[3].length();j++)
{
if(right_s[3][j]==temp_c)
{
flag[temp_c-'A']=1;
break;
}
}
} if(bala[1]=="up")
{
for(j=0;j<left_s[1].length();j++)
{
if(left_s[1][j]==temp_c)
{
if(flag[temp_c-'A']==1)
continue;
else
flag[temp_c-'A'] += 4;
}
}
for(j=0;j<right_s[1].length();j++)
{
if(right_s[1][j]==temp_c)
{
if(flag[temp_c-'A']==1)
continue;
else
flag[temp_c-'A'] += 3;
}
}
}
if(bala[2]=="up")
{
for(j=0;j<left_s[2].length();j++)
{
if(left_s[2][j]==temp_c)
{
if(flag[temp_c-'A']==1)
continue;
else
flag[temp_c-'A'] += 4;
}
}
for(j=0;j<right_s[2].length();j++)
{
if(right_s[2][j]==temp_c)
{
if(flag[temp_c-'A']==1)
continue;
else
flag[temp_c-'A'] += 3;
}
}
}
if(bala[3]=="up")
{
for(j=0;j<left_s[3].length();j++)
{
if(left_s[3][j]==temp_c)
{
if(flag[temp_c-'A']==1)
continue;
else
flag[temp_c-'A'] +=4;
}
}
for(j=0;j<right_s[3].length();j++)
{
if(right_s[3][j]==temp_c)
{
if(flag[temp_c-'A']==1)
continue;
else
flag[temp_c-'A'] +=3;
}
}
} if(bala[1]=="down")
{
for(j=0;j<left_s[1].length();j++)
{
if(left_s[1][j]==temp_c)
{
if(flag[temp_c-'A']==1)
continue;
else
flag[temp_c-'A'] +=3;
}
}
for(j=0;j<right_s[1].length();j++)
{
if(right_s[1][j]==temp_c)
{
if(flag[temp_c-'A']==1)
continue;
else
flag[temp_c-'A'] +=4;
}
}
}
if(bala[2]=="down")
{
for(j=0;j<left_s[2].length();j++)
{
if(left_s[2][j]==temp_c)
{
if(flag[temp_c-'A']==1)
continue;
else
flag[temp_c-'A'] +=3;
}
}
for(j=0;j<right_s[2].length();j++)
{
if(right_s[2][j]==temp_c)
{
if(flag[temp_c-'A']==1)
continue;
else
flag[temp_c-'A'] +=4;
}
}
}
if(bala[3]=="down")
{
for(j=0;j<left_s[3].length();j++)
{
if(left_s[3][j]==temp_c)
{
if(flag[temp_c-'A']==1)
continue;
else
flag[temp_c-'A'] +=3;
}
}
for(j=0;j<right_s[3].length();j++)
{
if(right_s[3][j]==temp_c)
{
if(flag[temp_c-'A']==1)
continue;
else
flag[temp_c-'A'] +=4;
}
}
}
}
for(temp_c='A';temp_c<='L';temp_c++)
{
num[flag[temp_c-'A']]++;
}
for(i=0;i<=12;i++)
{
if(num[i]==1 && i!=7 && i!=10 && i!=11)
{
for(temp_c='A';temp_c<='L';temp_c++)
{
if(flag[temp_c-'A']==i)
{
if(pend())
{
solve();
}
}
}
}
}
} return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 1013:Counterfeit Dollar的更多相关文章

  1. 九度OJ 1150:Counterfeit Dollar(假美元) (分析、检验)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:485 解决:215 题目描述: Sally Jones has a dozen Voyageur silver dollars. Howev ...

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

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

  3. POJ 1013 Counterfeit Dollar

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

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

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

  5. POJ1013 Counterfeit Dollar

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

  6. POJ 1013 小水题 暴力模拟

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

  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 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

随机推荐

  1. ubuntu18.04下neo4j的安装

    参考CSDN博客 安装jdk8方式与博客中有不同,按照博客中方法没有成功 以下方法配置环境变量成功 进入配置文件 [root@cuierdan java]# vim /etc/profile在文件的后 ...

  2. 在 Rolling Update 中使用 Health Check【转】

    上一节讨论了 Health Check 在 Scale Up 中的应用,Health Check 另一个重要的应用场景是 Rolling Update.试想一下下面的情况: 现有一个正常运行的多副本应 ...

  3. springboot整合logback集成elk实现日志的汇总、分析、统计和检索功能

    在Spring Boot当中,默认使用logback进行log操作.logback支持将日志数据通过提供IP地址.端口号,以Socket的方式远程发送.在Spring Boot中,通常使用logbac ...

  4. 四篇关于chen_zhe的美文

    壹   chen_zhe人 那是谁 是谁 是谁 那就是 chen_zhe chen_zhe人 chen_zhe人 背负着暴政之名 抛弃了一切(指民心)而战斗(指禁言)的男人 chen_zhe代码是超音 ...

  5. css3的伪(伪类和伪元素)大合集

    本文讲css3的伪,不是讲它有多虚伪,而是说它的伪元素样式.不得不说以前虽知html伪元素,但很少用,后得知借助css3伪元素可以发挥极大的便利.故总结css3的伪如下: CSS中存在一些比较特殊的属 ...

  6. 关于可持久化Trie

    我认为 可持久化Trie 主要指 可持久化01Trie 如洛谷P4735 将每个数的异或前缀和转化为二进制,添加前缀0至相同位数,然后从最高位开始插入,类似主席树,每一层都对需要更新的点加入一个新的点 ...

  7. JS - 获取页面滚动的高度

    document.documentElement.scrollTop||document.body.scrollTop

  8. idea 将java 项目 打包成jar包

    记录一下,防止忘记.ps : 请忽略这个是web项目 1.idea 打包jar包 (1)首先打开Project Structure,选中Artifacts (2)点击绿色加号,选中jar ,然后选中f ...

  9. 如何通过 Python 和 OpenCV 实现目标数量监控?

    今天我们将利用python+OpenCV实现对视频中物体数量的监控,达到视频监控的效果,比如洗煤厂的监控水龙头的水柱颜色,当水柱为黑色的超过了一半,那么将说明过滤网发生了故障.当然不仅如此,我们看的是 ...

  10. Flink Window窗口机制

    总览 Window 是flink处理无限流的核心,Windows将流拆分为有限大小的"桶",我们可以在其上应用计算. Flink 认为 Batch 是 Streaming 的一个特 ...