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 ...
随机推荐
- Swift语言实战晋级-第9章 游戏实战-跑酷熊猫-4 熊猫的跳和打滚
之前我们学会了跑的动作,现在我们可以利用同样的方法来实现了跳和打滚的动画. …… class Panda : SKSpriteNode { …… //跳的纹理集合 let jumpAtlas = SK ...
- PostgreSQL Obtaining the Result Status
There are several ways to determine the effect of a command. The first method is to use the GETDIAGN ...
- PostgreSQL Errors and Messages
使用RAISE语句来报告消息并抛出错误 RAISE [ level ] ’format’ [, expression [, ... ]] [ USING option = expression [, ...
- paper 69:Haar-like矩形遍历检测窗口演示Matlab源代码[转载]
Haar-like矩形遍历检测窗口演示Matlab源代码 clc; clear; close all; % Haar-like特征矩形计算 board = 24 % 检测窗口宽度 num = 24 % ...
- zw版【转发·台湾nvp系列例程】halcon与delphi系列例程
zw版[转发·台湾nvp系列例程]halcon与delphi系列例程 台湾nvp技术论坛,是目前halcon与delphi例程最多的网站,也是唯一成系列的, http://zip.nvp.com.tw ...
- jquery 下拉菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- android之费电检查 BetterBatteryStats
今天老大给了一个任务,是说我们的应用在后台时,还会比较费电!让我查一下 我立马头大了!无从下手! 一.赶紧百度,得到以下几个信息: ①费电的操作有:大数据量的传输;不停的在网络间切换;解析大量的文本数 ...
- 关于基于.NET Framework的网络通信程序底层扫盲
引自<三维游戏引擎的设计与实现>书中9.3节: 如果服务端在.Net Framework基础上开发,那么可以直接选择使用.Net Framework提供的Socket类, ...
- MessageDigest
转: 我们知道,编程中数据的传输,保存,为了考虑安全性的问题,需要将数据进行加密.我们拿数据库做例子.如果一个用户注册系统的数据库,没有对用户的信息进 行保存,如,我去页面注册,输入"Vic ...
- 关于mac book 的启动选项
苹果电脑是用EFI的,没有BIOS,唯一可以设置的是开机的启动选项.可以在基于 Intel 的 Mac 电脑上使用下列启动键组合启动时按住 C 键——从可启动 CD 或 DVD 光盘启动,如随机附带的 ...