模拟,找次品硬币,Counterfeit Dollar(POJ 1013)
题目链接:http://poj.org/problem?id=1013
解题报告:
1、由于次品的重量不清楚,用time['L'+1]来记录各个字母被怀疑的次数。为负数则轻,为正数则重。
2、用zero['L'+1]记录当天平结果是even时,硬币绝对是真,true;
#include <iostream>
#include <cmath> using namespace std; int main()
{
int t;
cin>>t;
while(t--)
{
char left[][],right[][],result[][]; int time['L'+]= {}; ///标记各个字母被怀疑的次数;
bool zero['L'+]= {false}; ///标记字母绝对是真币; for(int k=; k<; k++)
cin>>left[k]>>right[k]>>result[k]; for(int i=; i<; i++) ///3次判断
{
///检查天平状态
switch(result[i][])
{
case 'e':///天平平衡
{
for(int j=; left[i][j]!='\0'; j++)
{
zero[left[i][j]]=true; zero[right[i][j]]=true;
}
break;
}
case 'u':///天平右边轻些
{
for(int j=; left[i][j]!='\0'; j++)
{
time[left[i][j]]++; time[right[i][j]]--;
}
break;
}
case 'd':///天平右边重些
{
for(int j=; left[i][j]!='\0'; j++)
{
time[left[i][j]]--; time[right[i][j]]++;
}
break;
}
}
} int Max=-;///查找被怀疑程度最高的硬币
char alpha;
for(int j='A';j<='L';j++)
{
if(zero[j])
continue; if(Max<=abs(time[j]))
{
Max=abs(time[j]);
alpha=j;
}
}
cout<<alpha<<" is the counterfeit coin and it is ";
if(time[alpha]>)
cout<<"heavy.\n";
else cout<<"light.\n";
}
return ;
}
模拟,找次品硬币,Counterfeit Dollar(POJ 1013)的更多相关文章
- Poj 1013 Counterfeit Dollar / OpenJudge 1013(2692) 假币问题
1.链接地址: http://poj.org/problem?id=1013 http://bailian.openjudge.cn/practice/2692 http://bailian.open ...
- POJ 1013 Counterfeit Dollar
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36206 Accepted: 11 ...
- POJ 1013:Counterfeit Dollar
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42028 Accepted: 13 ...
- POJ 1013 小水题 暴力模拟
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35774 Accepted: 11 ...
- 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枚硬币,其中有一枚假币.所有钱币的外表都一样,所有真币的重量都一样,假币的重量与真币不同,但我们不知道假币的重量 ...
- Counterfeit Dollar -----判断12枚钱币中的一个假币
Counterfeit Dollar Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u ...
- poj1013.Counterfeit Dollar(枚举)
Counterfeit Dollar Time Limit: 1 Sec Memory Limit: 64 MB Submit: 415 Solved: 237 Description Sally ...
- 思维+模拟--POJ 1013 Counterfeit Dollar
Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver d ...
随机推荐
- pl/sql过期问题解决
第一步: 输入cmd进入命令窗口 命令窗口中输入 regedit HKEY_CURRENT_USER\Software\Allround Automations 删除Allround Automati ...
- linux 基础运维 之 Linux的闹钟
1. linux 删除一个文件的权限要看文件所在的目录的权限 删除文件需要对对这个目录拥有w权限 修改文件 查看文件的内容需要对文件有rw权限 删除 创建一个文件 需要对文件坐在地目录拥有wx权限2. ...
- 读取日志文件,搜索关键字,打印关键字前5行。yield、deque实例
from collections import deque def search(lines, pattern, history=5): previous_lines = deque(maxlen=h ...
- html 复选框checkbox
统计选中复选框的个数 <html> <head> <title> </title> <script> function static_num ...
- 安装 fedora 之后
下载zsh,并安装oh-my-zsh dnf install zsh -y 到github的oh-my-zsh上按照教程安装oh-my-zsh,配置主题为minimal,这个是个人比较喜欢的主题,因为 ...
- FFmpegInterop 库在 Windows 10 应用中的编译使用
FFmpegInterop 简介 FFmpegInterop 是微软推出的封装 FFmpeg 的一个开源库,旨在方便在 Windows 10.Windows 8.1 以及 Windows Phone ...
- 第一个servet(用注解),不用web.xml
环境: idea 1.新建模块 2.在蓝色src下新建一个包com.test 3.在包下新建servlet 4.写代码 package com.test; import javax.servlet.S ...
- HashMap和Hashtable存放null
Hashmap是可以放key为null的,Hashtable不能放key为null.hashtable放key为null会报空指针异常 1. hashmap put方法源码 public V put( ...
- hdu 3642 覆盖3次以上体积
http://www.cnblogs.com/kane0526/archive/2013/03/06/2947118.html 题目大意:给你n个立方体,求相交区域大于等于三次的体积和. 这题需要前面 ...
- sql: 生日赠品中的相关算法
---2013年10月9日生日,就以2012年9月1日至2013年8月31日計算 (因為係生日月份前兩個月之最後一天為結算日) DECLARE @birthday datetime,@now date ...