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],重物 ...
随机推荐
- 设置CentOS开机连接网络 Centos 开机启动网卡的设置方法
我们开机网卡不能启动所以只能使用 ifup eth0 (eth0指的网卡) 来启动了,但是每一次都这样感觉不方便希望开机自动启动网卡 后来百度搜索了一下发现可以通过修改网卡( ifcfg-eth0)参 ...
- 浅谈JavaScript性能
最近在JavaScript性能方面有所感悟,把我的经验分给大家: 说到JavaScript,就不得不说它的代码的运行速度—— 在我初学JavaScript的时候,只是觉得它是一个很强大的脚本.渐渐的, ...
- C#修改用户名
string strCmdText; strCmdText = "useraccount where name='" + 旧密码 + "' rename " + ...
- asterisk实时添加sip号码--sqlite篇
原文:asterisk实时添加sip号码--sqlite篇 asterisk实时添加sip号码--sqlite篇 今天尝试用了asterisk的实时模式,往sqlite里面添加一个sip帐号,无需重启 ...
- FineUI开发实践
ASP.NET-FineUI开发实践-7 摘要: 下拉显示grid列表.其实很简单,但是试了很多方法,水平有限,主要是都不好使,还是简单的好使了,分享下.先是看了看网上的,是直接写个了extjs控件类 ...
- javascript 学习总结(三)Boolean对象
Boolean对象 /* 创建 Boolean 对象的语法: new Boolean(value); //构造函数 Boolean(value); //转换函数 参数 value 由布尔对象存放的值或 ...
- 在SSIS中使用自定义的DLL文件
原文:在SSIS中使用自定义的DLL文件 步骤1.开发dll(需要签名) using System;using System.Collections.Generic;using System.Text ...
- Windows注册表的基本知识及应用
转帖:Windows注册表的基本知识及应用 2009-12-23 11:30:56 分类: Windows注册表的基本知识及应用 一.注册表的重要性 在DOS年代,对计算机的内存管理及系统配置主要通 ...
- Web层后端权限模块
从零开始编写自己的C#框架(19)——Web层后端权限模块 不知不觉本系统写了快三个月了,最近写页面的具体功能时感觉到有点吃力,很多地方如果张嘴来讲的话可以说得很细,很全面,可写成文字的话,就不太 ...
- IOS UI 第四篇:基本UI
ViewController 应用 再第一个XIB页面创建另一个XIB页面,并且通过按钮调用它 - (IBAction)GoSecond:(id)sender { secondVie ...