【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 ...
随机推荐
- 在SecureCRT中使用rz和sz传输文件
首先检查Centos中有没有安装 lrzsz sudo yum install lrzsz 使用yum install的时候碰到一个问题, 不知道是否和虚拟机环境有关 Existing lock /v ...
- [win]系统优化工具dism++
系统优化工具, 确实能将c盘扩大个2-3g. 主要是删除日志 优化系统等功能. https://www.chuyu.me/
- 条件变量pthread_cond_t怎么用
#include <pthread.h> #include <stdio.h> #include <stdlib.h> pthread_mutex_t mutex ...
- c++ 指针(一)
指针:是说指针名表示的是地址.是一个变量,存储的是值的地址,而不是值本身 *运算符被称为间接值或解除引用运算符也可以叫做取地址符 声明一个指针 int * p_data; * p_data的类型为in ...
- SQL基础之数据库快照
1.认识快照 如名字一样,数据库快照就可以理解为数据库某一时刻的照片,它记录了此时数据库的数据信息.如果要认识快照的本质,那就要了解快照的工作原理.当我们执行t-sql创建快照后,此时就会创建一个或多 ...
- HoloLens开发手记 - 测试 Testing
测试HoloLens应用的做法和测试Windows应用很类似.所有常规的内容都应该被考虑在内(功能.互操作性.性能.安全性.可靠性等等),然而有些特性是HoloLens特有的,在PC或者手机上无法测试 ...
- Trilateration三边测量定位算法
转载自Jiaxing / 2014年2月22日 基本原理 Trilateration(三边测量)是一种常用的定位算法: 已知三点位置 (x1, y1), (x2, y2), (x3, y3) 已知未知 ...
- Install Sogoupinyin in Ubuntu
If you use Ubuntu 15.10,search 'sogou' in Software Center.If you can see sogoupinyin there.You can g ...
- 东大OJ-Prim算法
1222: Sweep the snow 时间限制: 1 Sec 内存限制: 128 MB 提交: 28 解决: 18 [提交][状态][讨论版] 题目描述 After the big big s ...
- 【JavaEE企业应用实战学习记录】struts2登录
<%-- login.jsp Created by IntelliJ IDEA. User: Administrator Date: 2016/10/6 Time: 16:26 To chang ...