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],重物 ...
随机推荐
- 认识ASP.NET MVC6
认识ASP.NET MVC6 这篇文章说明下如何在普通编辑器下面开发mvc6应用程序. 上篇文章: 十分钟轻松让你认识ASP.NET 5(MVC6) 首先安装mvc6的nuget包: 可以看到在pro ...
- How to:Installshield判断操作系统是否为64位,并且为操作注册表进行设置
原文:How to:Installshield判断操作系统是否为64位,并且为操作注册表进行设置 IS脚本操作注册表在64位平台下必须有特殊的设置 if (SYSINFO.bIsWow64) then ...
- Ninject.Extensions.
最近在使用IoC进行一个较复杂的项目进行架构,在IoC的选择上让我很是纠结.首先我不喜欢大量的配置文件进行配置,那简直是噩梦,比学习一门编程语言还痛苦.我喜欢前一段时间看EF的CodeFirst的那种 ...
- [ACM] POJ 2506 Tiling (递归,睑板)
Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7487 Accepted: 3661 Descriptio ...
- leetcode[90] Decode Ways
题目:如下对应关系 'A' -> 1 'B' -> 2 ... ‘Z’ -> 26 现在给定一个字符串,返回有多少种解码可能.例如:Given encoded message &qu ...
- extjs 时间可选择时分
new Ext.form.DateTimeField({ id: 'SdDateField', width: 130, format: 'Y-m-d H:i', editable: false, va ...
- asp.net、mvc、ajax、js、jquery、sql、EF、linq、netadvantage第三方控件知识点笔记
很简单,如下: 父页面:(弹出提示框) function newwindow(obj) { var rtn = window.showModalDialog('NewPage.htm','','sta ...
- [置顶] Hibernate从入门到精通(十)多对多单向关联映射
上一篇文章Hibernate从入门到精通(九)一对多双向关联映射中我们讲解了一下关于一对多关联映射的相关内容,这次我们继续多对多单向关联映射. 多对多单向关联映射 在讲解多对多单向关联映射之前,首先看 ...
- Linq无聊练习系列1--where练习
linq主要有3种,linq to sql,linq to XML,Linq to Object linq to sql. 这里没有通过相应的类,生成相应的数据库中的表.没有用流行的编码优先. 只是为 ...
- Binder机制,从Java到C (10. Binder驱动)
Binder驱动的代码都在kernel里面,这里就简单讲一下里面涉及到的几个东西: 1.MemoryBinder其实本质上就是一中数据传输方式,这种方式是通过binder driver实现的. 我们知 ...