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.

水题,思维,模拟的方式比较精巧。

#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int n, cnt, max;
string s1, s2, temp;
int flag[12];
cin>>n;
while (n--)
{
memset(flag, 0, sizeof(flag));
for (int t = 1; t <= 3; ++t)
{
cin >> s1 >> s2 >> temp;
if (temp=="even")
{
for (int i=0; i <s1.size(); ++i)
{
flag[s1[i] - 'A'] = 10;
flag[s2[i] - 'A'] = 10;
}
}
else if (temp== "up")
{
for (int i=0; i <s1.size(); ++i)
{
if (flag[s1[i] - 'A'] != 10)
++flag[s1[i] - 'A'];
if (flag[s2[i] - 'A'] != 10)
--flag[s2[i] - 'A'];
}
}
else
{
for (int i=0; i <s1.size(); ++i)
{
if (flag[s1[i] - 'A'] != 10)
--flag[s1[i] - 'A'];
if (flag[s2[i] - 'A'] != 10)
++flag[s2[i] - 'A'];
}
}
}
max =cnt = 0;
for (int i=0; i < 12; ++i)
{
if (flag[i] == 10)
continue;
if (max <= abs(flag[i]))
{
max = abs(flag[i]);
cnt = i;
}
}
if (flag[cnt] > 0)
printf("%c is the counterfeit coin and it is heavy.\n", 'A' + cnt);
else
printf("%c is the counterfeit coin and it is light.\n", 'A' + cnt);
}
return 0;
}

思维+模拟--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

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

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

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

  4. POJ 1013:Counterfeit Dollar

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

  5. POJ 1013 小水题 暴力模拟

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

  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. Counterfeit Dollar -----判断12枚钱币中的一个假币

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

  9. poj1013.Counterfeit Dollar(枚举)

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

随机推荐

  1. python通过pymysql实现数据库的增删改查

    今天实现了python对于数据库的增删改查工作: 具体的每一步的数据库的增删盖茶自己都实验过了. 掌握了基本的数据库操作语言.然后就是对于tuple()的认识. 以及对于查询语句中的:fetchone ...

  2. django->model模型操作(数据库操作)

    一.字段类型 二.字段选项说明 三.内嵌类参数说明abstract = Truedb_table = 'table_name' #表名,默认的表名是app_name+类名ordering = ['id ...

  3. VirtualBox的四种网络连接方式【转】

    VirtualBox中有4中网络连接方式: NAT Bridged Adapter Internal Host-only Adapter VMWare中有三种,其实他跟VMWare 的网络连接方式都是 ...

  4. 如何实现Jenkins 编译结果通知到QQ好友及QQ群组<很遗憾 2019年1月1日腾讯停止了webqq机器人的服务支持>

    Jenkins-NotifyQQ NotifyQQ 运行于Docker 本文介绍mac 环境下实现Jenkins编译结果QQ即时通知 Jenkins 安装使用及iOS自动化打包,邮件通知请参考本人博客 ...

  5. WPF 仿语音播放 自定义控件

    原理很简单,利用Path画一个图,然后用动画进行播放,播放时间由依赖属性输入赋值与控件内部维护的一个计时器进行控制. 控件基本是玩具,无法作为真实项目使用. 非专业UI,即使知道怎么画图也是画的不如意 ...

  6. centos7用户管理及root忘记密码恢复

    查看用户相关命令:#id 用户和组的信息#whoami #查看当前有效用户名#who #显示目前登入系统的用户信息.#w # w 命令用于显示已经登陆系统的用户列表#users #用于显示当前登录系统 ...

  7. Salesforce 学习 | 官方总结最实用的Spring '20新功能

    在Spring '20正式发布之前,Trailblazers 社区举行了一个名为Treasure Hunt的在线活动,通过预览沙盒,分享他们认为Spring ‘20中最重要的功能.这篇文章就来盘点一下 ...

  8. python基础:如何使用python pandas将DataFrame转换为dict

    之前在知乎上看到有网友提问,如何将DataFrame转换为dict,专门研究了一下,pandas在0.21.0版本中是提供了这个方法的.下面一起学习一下,通过调用help方法,该方法只需传入一个参数, ...

  9. 一道简单的SQL注入题

    这是我真正意义上来说做的第一道SQL题目,感觉从这个题目里还是能学到好多东西的,这里记录一下这个题目的writeup和在其中学到的东西 link:https://www.ichunqiu.com/ba ...

  10. JS:document.documentElement对象的

    document.documentElement.clientWidth 获取浏览器窗口文档显示区域的宽度,不包括滚动条. document.documentElement.clientHeight ...