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 ...
随机推荐
- JavaScript要点 (五) 函数定义
JavaScript 使用关键字 function 定义函数. 函数可以通过声明定义,也可以是一个表达式. 函数声明分号是用来分隔可执行JavaScript语句. 由于函数声明不是一个可执行语句,所以 ...
- java图片处理
import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import ja ...
- iOS开发-分页栏和选取器的使用
一.分页栏 创建一个新的项目,Subclass of的值选中UIViewController,然后在storyboard中删除根视图,在右下方拖出一个Tab Bar Controller 新增分页,只 ...
- CSDN首页> 移动开发 直接拿来用!最火的Android开源项目(完结篇)
此前,CSDN移动频道推出的GitHub平台上“最受欢迎的开源项目”系列文章引发了许多读者的热议,在“直接拿来用!最火的Android开源项目”系列文章(一).(二)中,我们也相继盘点了40个GitH ...
- linux下eclipse的安装
Eclipse的安装http://java.sun.com/javace/downloads/index.jsp下载:Jdk-6u17-linux-i586.binhttp://www.eclipse ...
- dos常用文件操作命令
1.DIR 含义: 显示指定目录下的文件和子目录列表 类型: 内部命令 格式: DIR[drive:][path][filename][/p][/w][/A[[:]attributes]][/O[[: ...
- Android_listView_BaseAdapter_downLoadImg
layout.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" x ...
- 不使用var定义变量和使用var的区别
最基本的var关键字是上下文的,而不采用var是全局的这就不讨论了 “不管是使用var关键字(在全局上下文)还是不使用var关键字(在任何地方),都可以声明一个变量”.这貌似一个错误的概念:任何时候, ...
- 实例化的两种方法(new和函数法)
// 定义类 类名字是 classA function classA(){ this.b=1; } classA.prototype.b=44; classA.prototype.s ...
- [引]ASP.NET MVC 4 Content Map
本文转自:http://msdn.microsoft.com/en-us/library/gg416514(v=vs.108).aspx The Model-View-Controller (MVC) ...