【poj1013】 Counterfeit Dollar
http://poj.org/problem?id=1013 (题目链接)
题意
12个硬币中有1个是假的,给出3次称重结果,判断哪个硬币是假币,并且判断假币是比真币中还是比真币轻。
Solution
很久以前写的题了,现在翻了翻发现思路还是不错的。
http://blog.csdn.net/lyy289065406/article/details/6661421
细节
像这种比较水的与字符串相关的题目用string做一些处理会方便很多,然而这道题好像都差不多。
代码
// poj1013
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<string>
#define MOD 1000000007
#define inf 2147483640
#define LL long long
#define free(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout);
using namespace std;
inline LL getint() {
LL x=0,f=1;char ch=getchar();
while (ch>'9' || ch<'0') {if (ch=='-') f=-1;ch=getchar();}
while (ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
return x*f;
} int a[12];
string s1,s2,s3; int main() {
int T;
scanf("%d",&T);
while (T--) {
int cnt=0;
for (int i=0;i<12;i++) a[i]=0;
for (int o=1;o<=3;o++) {
cin>>s1>>s2>>s3;
if (s3=="up") {
for (int j=0;j<(int)s1.size();j++) a[s1[j]-'A']++;
for (int j=0;j<(int)s2.size();j++) a[s2[j]-'A']--;
cnt++;
}
if (s3=="down") {
for (int j=0;j<(int)s1.size();j++) a[s1[j]-'A']--;
for (int j=0;j<(int)s2.size();j++) a[s2[j]-'A']++;
cnt++;
}
if (s3=="even")
for (int j=0;j<(int)s1.size();j++) a[s1[j]-'A']=a[s2[j]-'A']=6;
}
for (int i=0;i<12;i++) {
if (a[i]==cnt) printf("%c is the counterfeit coin and it is heavy.\n",i+'A');
if (a[i]==-cnt) printf("%c is the counterfeit coin and it is light.\n",i+'A');
}
}
return 0;
}
【poj1013】 Counterfeit Dollar的更多相关文章
- POJ1013 Counterfeit Dollar
题目来源:http://poj.org/problem?id=1013 题目大意:有12枚硬币,其中有一枚假币.所有钱币的外表都一样,所有真币的重量都一样,假币的重量与真币不同,但我们不知道假币的重量 ...
- poj1013.Counterfeit Dollar(枚举)
Counterfeit Dollar Time Limit: 1 Sec Memory Limit: 64 MB Submit: 415 Solved: 237 Description Sally ...
- POJ1013称硬币【枚举】
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 52474 Accepted: 16 ...
- 【POJ1568】【极大极小搜索+alpha-beta剪枝】Find the Winning Move
Description 4x4 tic-tac-toe is played on a board with four rows (numbered 0 to 3 from top to bottom) ...
- 【DataStructure】Description and Introduction of Tree
[Description] At ree is a nonlinear data structure that models a hierarchical organization. The char ...
- 【转】NPOI使用手册
[转]NPOI使用手册 NPOI使用手册 目录 1.认识NPOI 2. 使用NPOI生成xls文件 2.1 创建基本内容 2.1.1创建Workbook和Sheet 2.1.2创建DocumentSu ...
- 【背包问题】PACKING
题目描述 It was bound to happen. Modernisation has reached the North Pole. Faced with escalating costs ...
- Python高手之路【六】python基础之字符串格式化
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...
- 【原】谈谈对Objective-C中代理模式的误解
[原]谈谈对Objective-C中代理模式的误解 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 这篇文章主要是对代理模式和委托模式进行了对比,个人认为Objective ...
随机推荐
- 如何把Json格式字符写进text文件中
本篇一步一步学习怎样把显示于网页的json格式的字符串写进text文件中,并保存起来.学习到创建model, Entity, 序列化List<object>转换为json,显示于网页上.然 ...
- 打字机游戏Ⅱ之手速pk
前言 demo预览->typewriter gameⅡ (chrome only 没做兼容) 别看一开始时速度不快,会线性增长的哦,反正楼主的score还没达到过40... 为什么叫Ⅱ呢?之前写 ...
- 建立时间和保持时间(setup time 和 hold time)
建立时间和保持时间贯穿了整个时序分析过程.只要涉及到同步时序电路,那么必然有上升沿.下降沿采样,那么无法避免setup-time 和 hold-time这两个概念.本文内容相对独立于该系列其他文章,是 ...
- MVC Form异步请求
@using (Ajax.BeginForm("CreateReviewInfo", "Review", new AjaxOptions { HttpMetho ...
- C#开发Windows服务
Microsoft Windows 服务(即,以前的 NT 服务)使您能够创建在它们自己的 Windows 会话中可长时间运行的可执行应用程序. 服务可以在计算机启动时自动启动,可以暂停和重新启动而且 ...
- Code First操作Mysql数据库
前面博客也讲了,自己做一个网站,选用的是MVC+EF Code First+MySql+EasyUI,先说下技术选型.一.为什么选择MVC? 因为之前自己做的系统大部分是webForm,MVC的之前也 ...
- [C语言]一个很实用的服务端和客户端进行UDP通信的实例
前段时间发了个TCP通信的例子,现在再来一个UDP通信的例子.这些可以作为样本程序,用到开发中.“裸写”socket老是记不住步骤,经常被鄙视…… 下面的例子很简单,写一个UDP的server用于收包 ...
- [BZOJ2429][HAOI2006]聪明的猴子(MST)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2429 分析:要让最大的最小,所以就是最小生成树上的啦,于是问题就变成了有多少个猴子&g ...
- STL中algorithm里的查找
首先,选择查找算法时,区间是否排序是一个至关重要的因素.可以按是否需要排序区间分为两组: A. count,find B. binary_search,lower_bound,upper_bound, ...
- 2-ls 显示目录内容
ls list directory contents 显示目录内容 [语法]: ls [选项] [参数] [功能介绍] ls指令用来显示目录列表,在Linux系统中有着较高的使用率.ls指令的输出信息 ...