POJ 1013 小水题 暴力模拟
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 35774 | Accepted: 11390 |
Description
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
Output
Sample Input
1
ABCD EFGH even
ABCI EFJK up
ABIJ EFGH even
Sample Output
K is the counterfeit coin and it is light.
Source
题意 :
有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 小水题 暴力模拟的更多相关文章
- poj 1005:I Think I Need a Houseboat(水题,模拟)
I Think I Need a Houseboat Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 85149 Acce ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- hdu 2117:Just a Numble(水题,模拟除法运算)
Just a Numble Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu5007 小水题
题意: 给你一个串,如果出现子串 "Apple", "iPhone", "iPod", "iPad"输出MA ...
- poj 3264 RMQ 水题
题意:找到一段数字里最大值和最小值的差 水题 #include<cstdio> #include<iostream> #include<algorithm> #in ...
- Poj 1552 Doubles(水题)
一.Description As part of an arithmetic competency program, your students will be given randomly gene ...
- hdu 4540 威威猫系列故事——打地鼠 dp小水题
威威猫系列故事——打地鼠 Time Limit: 300/100 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total ...
- Crashing Robots(水题,模拟)
1020: Crashing Robots 时间限制(普通/Java):1000MS/10000MS 内存限制:65536KByte 总提交: 207 测试通过:101 ...
- POJ 1837 Balance 水题, DP 难度:0
题目 http://poj.org/problem?id=1837 题意 单组数据,有一根杠杆,有R个钩子,其位置hi为整数且属于[-15,15],有C个重物,其质量wi为整数且属于[1,25],重物 ...
随机推荐
- 【iOS】iOS它Container View获得ViewController
近期使用Container View来在主View Controller建立自己的子Controller,但是遇到问题.不知道怎样用代码获取Controller View附带的View Control ...
- CSS知识总结之设计模式(持续学习中)
OOCSS 参考:http://coding.smashingmagazine.com/2011/12/12/an-introduction-to-object-oriented-css-oocss ...
- 快速构建Windows 8风格应用16-SettingContract原理及构建
原文:快速构建Windows 8风格应用16-SettingContract原理及构建 本篇博文主要介绍Setting Contract概述.Setting Contract实现基本原理.如何构建Se ...
- 开源的.Net ORM微型框架SuperHelper
SuperHelper——灵活通用的.开源的.Net ORM微型框架 SuperHelper是博主利用业余时间编写的一个ORM微型框架,除了可以提高开发效率,与其它ORM框架相比,博主更加喜欢Supe ...
- [译]Java设计模式之解释器
(文章翻译自Java Design Pattern: Interpreter) 解释器模式适用于当一些内容需要翻译的时候.下面的例子是一个非常简单的解释器实现.它将字母"a"和&q ...
- leetcode第八题--String to Integer (atoi)
Problem: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible inp ...
- css-fixed兼容写法
解决IE6中fixed闪动问题(效果稍微好一点,不能完全解决闪动问题) *{background-image:url(about:blank);background-attachment:fixed; ...
- 如何在在网页上显示pdf文档
------解决方案--------------------通过flash插件 ------解决方案--------------------RAD PDF Release 2.7 http://www ...
- Xamarin Mono 环境搭建
Xamarin Mono 环境搭建(使用Visual Studio 2013 开发android 和 ios ) 本文主要介绍Xamarin结合VS2013来开发Android应用程序,主要会介绍Mo ...
- wcf的binding和host
----------------------------Binding绑定:定义:绑定表示通讯信道的配置:定义了客户端与服务端之间的协议:---传输协议:http.tcp.命名管道.msmq,自定义( ...