Counterfeit Dollar 分类: POJ 2015-06-12 15:28 19人阅读 评论(0) 收藏
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 41559 | Accepted: 13237 |
Description
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
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
Sample Input
1
ABCD EFGH even
ABCI EFJK up
ABIJ EFGH even
Sample Output
K is the counterfeit coin and it is light./*
不知道为什么abs()函数一用就CE ,无奈就只能改成这样后来用c++交就没事了,G++硬伤
*/
#include <cstdio>
#include <string.h>
#include <cmath>
char s[3][3][13];
int a[12];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
for(int i=0; i<3; i++)
{
scanf("%s %s %s",s[i][0],s[i][1],s[i][2]);
}
memset(a,0,sizeof(a));
for(int i=0; i<3; i++)
{
int len=strlen(s[i][0]);
if(strcmp(s[i][2],"even")==0)
{
for(int j=0; j<len; j++)
{
a[s[i][0][j]-'A']=141;
a[s[i][1][j]-'A']=141;
}
}
else if(strcmp(s[i][2],"up")==0)
{
for(int j=0; j<len; j++)
{
if(a[s[i][0][j]-'A']!=141)//不要忘加判断
{
a[s[i][0][j]-'A']++;
}
if(a[s[i][1][j]-'A']!=141)
{
a[s[i][1][j]-'A']--;
}
}
}
else if(strcmp(s[i][2],"down")==0)
{ for(int j=0; j<len; j++)
{
if(a[s[i][0][j]-'A']!=141)
{
a[s[i][0][j]-'A']--;
}
if(a[s[i][1][j]-'A']!=141)
{
a[s[i][1][j]-'A']++;
}
}
}
}
int Max=0;
int flag=0;
for(int i=0; i<12; i++)
{
if(a[i]!=141)
{
if(Max<fabs(a[i]))//绝对值最大怀疑的次数最多就是假币
{
Max=fabs(a[i]);
flag=i;
}
}
}
if(a[flag]<=0)//还要判断轻重
printf("%c is the counterfeit coin and it is light.\n",flag+'A');
else
{
printf("%c is the counterfeit coin and it is heavy.\n",flag+'A');
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
Counterfeit Dollar 分类: POJ 2015-06-12 15:28 19人阅读 评论(0) 收藏的更多相关文章
- 【solr基础教程之九】客户端 分类: H4_SOLR/LUCENCE 2014-07-30 15:28 904人阅读 评论(0) 收藏
一.Java Script 1.由于Solr本身可以返回Json格式的结果,而JavaScript对于处理Json数据具有天然的优势,因此使用JavaScript实现Solr客户端是一个很好的选择. ...
- Borg Maze 分类: POJ 2015-07-27 15:28 5人阅读 评论(0) 收藏
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9971 Accepted: 3347 Description The B ...
- PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...
- POJ 1068 AC 2014-01-07 15:24 146人阅读 评论(0) 收藏
POJ的题目都是英文的,所以,,,还是直接贴代码吧 #include<stdio.h> int main(){ int x,y,z; int n,nm,max; scanf("% ...
- 周赛-DZY Loves Chessboard 分类: 比赛 搜索 2015-08-08 15:48 4人阅读 评论(0) 收藏
DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input standard ...
- cf 61E. Enemy is weak 树状数组求逆序数(WA) 分类: Brush Mode 2014-10-19 15:16 104人阅读 评论(0) 收藏
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> ...
- max_flow(Dinic) 分类: ACM TYPE 2014-09-02 15:42 94人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> #include<queue> #in ...
- SQL 分组 加列 加自编号 自编号限定 分类: SQL Server 2014-11-25 15:41 283人阅读 评论(0) 收藏
说明: (1)日期以年月形式显示:convert(varchar(7),字段名,120) , (2)加一列 (3)自编号: row_number() over(order by 字段名 desc) a ...
- SQL 按月统计(两种方式) 分类: SQL Server 2014-08-04 15:36 154人阅读 评论(0) 收藏
(1)Convert 函数 select Convert ( VARCHAR(7),ComeDate,120) as Date ,Count(In_code) as 单数,Sum(SumTrueNum ...
随机推荐
- Git_Commands
- 弱类型变量原理探究(转载 http://www.csdn.net/article/2014-09-15/2821685-exploring-of-the-php)
N首页> 云计算 [问底]王帅:深入PHP内核(一)——弱类型变量原理探究 发表于2014-09-19 09:00| 13055次阅读| 来源CSDN| 36 条评论| 作者王帅 问底PHP王帅 ...
- Android自定义ScrollView实现一键置顶功能
效果图如下: (ps:动态图有太大了,上传不了,就给大家口述一下要实现的功能吧) 要实现的功能:当ScrollView向上滑动超过一定距离后,就渐变的出现一个置顶的按钮,当滑动距离小于我们指定的距离时 ...
- kafka管理器kafka-manager部署安装
运行的环境要求 Kafka 0.8.1.1+ sbt 0.13.x Java 7+ 功能 为了简化开发者和服务工程师维护Kafka集群的工作,yahoo构建了一个叫做Kafka管理器的基于Web工具, ...
- My sql 日期格式化
DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据. 语法 DATE_FORMAT(date,format) select DATE_FORMAT(NOW(),'%Y-%m-%d %H ...
- highcharts 实例
<script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript">< ...
- 夺命雷公狗—angularjs—10—angularjs里面的内置函数
我们没学一门语言或者框架,几乎里面都有各自的语法和内置函数,当然,强悍的angularjs也不例外,他的方法其实常用的没多少,因为很多都可以用源生jis几乎都能完成一大部分.. <!doctyp ...
- 夺命雷公狗---Thinkphp----7之栏目配合Model的增删改查
我们首先来写一个查: public function lists(){ $type = M('Type')->select(); $this -> assign('type',$type) ...
- PAT乙级 1031. 查验身份证(15) 标志要清零!!!!!!!!!
1031. 查验身份证(15) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 一个合法的身份证号码由17位地区. ...
- PIC18F中断定时器
//基于MCC18编译器,使用HI-PICC不可用 //-------------------------------------------- #include <p18F452.h> ...