Poj 1013 Counterfeit Dollar / OpenJudge 1013(2692) 假币问题
1.链接地址:
http://poj.org/problem?id=1013
http://bailian.openjudge.cn/practice/2692
http://bailian.openjudge.cn/practice/1013
2.题目:
Counterfeit Dollar
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37454 Accepted: 11980 Description
Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver dollars; one coin is counterfeit even though its color and size make it indistinguishable from the real silver dollars. The counterfeit 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
The
first line of input is an integer n (n > 0) specifying the number of
cases to follow. Each case consists of three lines of input, one for
each weighing. Sally has identified each of the coins with the letters
A--L. Information 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
For
each case, the output will identify the counterfeit coin by its letter
and tell whether it is heavy or light. The solution will always be
uniquely determined.Sample Input
1
ABCD EFGH even
ABCI EFJK up
ABIJ EFGH evenSample Output
K is the counterfeit coin and it is light.Source
3.思路:
枚举法,枚举全部情况即可
4.代码:
#include <iostream>
#include <cstdio>
#include <string> using namespace std; int main()
{
string str_left[];
string str_right[];
string str_res[]; int n;
cin>>n; int i,j,k; while(n--)
{
for(i = ; i < ; ++i) cin>>str_left[i]>>str_right[i]>>str_res[i];
for(i = ; i < ; ++i)
{
for(j = ; j < ; ++j)
{
for(k = ; k < ; ++k)
{
char ch = 'A' + i;
string::size_type idx_left = str_left[k].find(ch);
string::size_type idx_right = str_right[k].find(ch); if(idx_left != string::npos)
{
if(j == ) //heavy
{
if(str_res[k] != "up") break;
}
else
{
if(str_res[k] != "down") break;
}
}
else if(idx_right != string::npos)
{
if(j == )
{
if(str_res[k] != "down") break;
}
else
{
if(str_res[k] != "up") break;
}
}
else
{
if(str_res[k] != "even") break;
} }
if(k >= ) break;
}
if(j < ) break;
}
if(j == ) cout<<(char)('A' + i)<<" is the counterfeit coin and it is heavy."<<endl;
else cout<<(char)('A' + i)<<" is the counterfeit coin and it is light."<<endl;
}
return ;
}
Poj 1013 Counterfeit Dollar / OpenJudge 1013(2692) 假币问题的更多相关文章
- POJ 1013 Counterfeit Dollar
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36206 Accepted: 11 ...
- POJ 1013 Counterfeit Dollar 集合上的位运算
Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are t ...
- 思维+模拟--POJ 1013 Counterfeit Dollar
Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver d ...
- POJ 1013:Counterfeit Dollar
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42028 Accepted: 13 ...
- Counterfeit Dollar -----判断12枚钱币中的一个假币
Counterfeit Dollar Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u ...
- Counterfeit Dollar 分类: POJ 2015-06-12 15:28 19人阅读 评论(0) 收藏
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 41559 Accepted: 13 ...
- 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 ...
- 模拟,找次品硬币,Counterfeit Dollar(POJ 1013)
题目链接:http://poj.org/problem?id=1013 解题报告: 1.由于次品的重量不清楚,用time['L'+1]来记录各个字母被怀疑的次数.为负数则轻,为正数则重. 2.用zer ...
随机推荐
- cocos2d-x 判断系统语言
转自:http://blog.csdn.net/tangaowen/article/details/8878193 //default language is local language ccLan ...
- 函数中的$input
$input 在此属于一个特殊变量,一般在函数中用于接收输入 function FindWindowsFolder { $input | where-object {$_.Name -eq " ...
- 从零开始学android开发-查看sqlite数据库
C:\Users\Administrator>cd E:\ProSoft\adt-bundle-windows-x86-20140321\sdk\platform-tools
- Codeforces Round #319 (Div. 1) C. Points on Plane 分块
C. Points on Plane Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/576/pro ...
- 在centos上使用yum安装redis及php扩展php-redis
.wget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -ivh epel-rele ...
- Zend Studio 10正式版注册破解
1.文件和汉化文件 ZendStudio官方下载地址:http://www.geekso.com/component/zendstudio-downloads/ 百度云地址: 10.0.0.msi文件 ...
- java_利用session校验图片认证码
RegisterServlet:检验server,client验证码是否一致 ImageServlet: 产生验证码 <!DOCTYPE html> <html> <he ...
- C#基础篇--文件(流)
1:Path类是专门用来操作文件路径的(Path类是静态类):当然用字符串的处理办法也能实现. string str = @"C:\Users\成才\Desktop\Hashtable.t ...
- Swift超详细的基础语法-结构体,结构体构造器,定义成员方法, 值类型, 扩充函数
知识点 基本概念 结构体的基本使用 结构体构造器(构造函数/构造方法) 结构体扩充函数(方法), 又称成员方法 结构体是值类型 1. 基本概念 1.1 概念介绍 结构体(struct)是由一系列具有相 ...
- Android_Intent_passValue(4)
xml布局文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...