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

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

East Central North America 1998

题意 :

 有12个硬币 有一个是假的 比其他的或轻或重     分别标记为A到L

然后输入cas 有个cas组数据

每组输入3行 每行3个字符串 第一个表示当时天平上左边有哪几个字符  第二个是右边 2边个数一样 但是不一定有几个    之后第三个字符串描述左边是比右边大小还是相等

问你  哪一个硬币是假的  假的相对于真的是清还是重        

保证有解

思路:暴力模拟 暴力哪一个是假的  总共只有12个  很好暴力

#include<stdio.h>
#include<string.h>
int a[100];
char s[3][3][20];
int solve()
{
int i,j,k,len,n1,n2;
for(k=0;k<3;k++)
{
n1=0;n2=0;
len=strlen(s[k][0]);
for(i=0;i<len;i++)
n1+=a[s[k][0][i]-'A'];
for(i=0;i<len;i++)
n2+=a[s[k][1][i]-'A'];
if(strcmp(s[k][2],"even")==0)
if(n1!=n2) break;
if(strcmp(s[k][2],"up")==0)
if(n1<=n2) break;
if(strcmp(s[k][2],"down")==0)
if(n1>=n2) break;
}
if(k==3) return 1;
return 0;
}
int main()
{
int cas,i,j,flag;
scanf("%d",&cas);
while(cas--)
{
flag=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%s",s[i][j]);
for(i=0;i<12;i++) a[i]=2;
for(i=0;i<12;i++)
{
a[i]=1;
if(solve())
{
flag=1;
printf("%c is the counterfeit coin and it is light.\n",i+'A');
}
if(flag) break;
a[i]=2;
}
if(flag) continue;
for(i=0;i<12;i++) a[i]=1;
for(i=0;i<12;i++)
{
a[i]=2;
if(solve())
{
flag=1;
printf("%c is the counterfeit coin and it is heavy.\n",i+'A');
}
if(flag) break;
a[i]=1;
}
}
return 0;
}

POJ 1013 小水题 暴力模拟的更多相关文章

  1. poj 1005:I Think I Need a Houseboat(水题,模拟)

    I Think I Need a Houseboat Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 85149   Acce ...

  2. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  3. hdu 2117:Just a Numble(水题,模拟除法运算)

    Just a Numble Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  4. hdu5007 小水题

    题意:       给你一个串,如果出现子串 "Apple", "iPhone", "iPod", "iPad"输出MA ...

  5. poj 3264 RMQ 水题

    题意:找到一段数字里最大值和最小值的差 水题 #include<cstdio> #include<iostream> #include<algorithm> #in ...

  6. Poj 1552 Doubles(水题)

    一.Description As part of an arithmetic competency program, your students will be given randomly gene ...

  7. hdu 4540 威威猫系列故事——打地鼠 dp小水题

    威威猫系列故事——打地鼠 Time Limit: 300/100 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total ...

  8. Crashing Robots(水题,模拟)

    1020: Crashing Robots 时间限制(普通/Java):1000MS/10000MS     内存限制:65536KByte 总提交: 207            测试通过:101 ...

  9. POJ 1837 Balance 水题, DP 难度:0

    题目 http://poj.org/problem?id=1837 题意 单组数据,有一根杠杆,有R个钩子,其位置hi为整数且属于[-15,15],有C个重物,其质量wi为整数且属于[1,25],重物 ...

随机推荐

  1. archlinux的wiki非常强壮

    最近发现搜索linux工具或系统配置内容.来自同一个站点很多很好的资源:https://www.archlinux.org/,网站wiki(https://wiki.archlinux.org/)中有 ...

  2. git上自然框架源码

    [自然框架]终于把源码弄到git上吗了 2015-02-02 14:38 by 金色海洋(jyk)阳光男孩, 183 阅读, 6 评论, 收藏, 编辑 好久没写博客了,发现又从左面的排名里掉出去了. ...

  3. HEAP CORRUPTION DETECTED

    发生主要是由于这个问题给写入超出预分配的空间,注意检查越界情况 版权声明:本文博客原创文章,博客,未经同意,不得转载.

  4. 关于ligerform中select与text的赋值与取值

    如有下ligerform表单: var formData = [ { display: "区域", name: "QYYJ", newline: true, l ...

  5. WEB浏览器与服务器通讯过程

    以访问网页www.baidu.com为例,下面是使用Wireshark捕捉到的数据: 浏览器先发起一个TCP连接,然后发送GET报文给服务器,服务器之后返回一个Response报文. 从服务器端返回时 ...

  6. leetcode第四题--Add Two Numbers

    Problem: You are given two linked lists representing two non-negative numbers. The digits are stored ...

  7. Dotfuscator自定义规则中的元素选择

    Dotfuscator是专业的.NET程序代码保护软件.是支持规则自定义的,你可以对重命名.程序控制流.字符串加密等等功能自定义规则.在进行规则自定义过程中,可以通过元素的不同选择,满足自己的程序需要 ...

  8. 安装Windows2012操作系统 - 初学者系列 - 学习者系列文章

    Windows 2012是微软最新的服务器操作系统,估计在国外服务器空间的运营商安装的比较多些吧.下面简要介绍下该操作系统的安装. 1.  将光盘放入光驱.进入BIOS设置成光驱启动.重启计算机. 2 ...

  9. 使用Oracle 9i工具管理数据库 - 初学者系列 - 学习者系列文章

    前面介绍了Oracle 9i的安装,本文大概介绍下Oracle 9i提供的管理工具的使用. 1 打开数据库配置工具 2 下一步 3 下一步 4 下一步.这里输入数据库名和SID 5 下一步 6 下一步 ...

  10. 强大的jquery-制作选项卡

    最近在学习jquery,特地把今天写的一个选项卡源码贴出来.只是做只是梳理,大神们请不要吐槽,如果有更好的方法,欢迎指点.谢谢. css <style> #tab div{ width:2 ...