HDU 2986 Ballot evaluation(精度问题)
题意 : 给你n个人名,每个名后边跟着一个数,然后m个式子,判断是否正确。
思路 :算是一个模拟吧,但是要注意浮点数容易丢失精度,所以要好好处理精度,不知道多少人死在精度上,不过我实在是不怎么会处理精度,所以我就让那个数变为字符串输入然后在处理,相当于乘上10,但是直接乘上10,数容易变,不知道的自己可以试一下。
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <string>
#include <map>
#include <algorithm> using namespace std;
string name[] ;
string score ;
char ch[] ;
int yun ;
int main()
{
int p,g ,x,m;
scanf("%d %d",&p,&g) ;
map<string,int >mp ;
for(int i = ; i < p ; i++)
{
cin>>name[i]>>score ;
m = ;
int len = score.size() ;
m += score[len-]-'' ;
int j;
for(j = ; j < len ; j++)
if(score[j] == '.') break ;
int n = ;
// printf("%d*\n",j) ;
for(int k = j- ; k >= ; k--)
{
m += (score[k]-'')*n ;
n = n* ;
}
mp[name[i]] = m ;
// printf("#%d#\n",mp[name[i]]) ;
}
for(int i = ; i <= g ; i++)
{
int sum = ;
while(true)
{
scanf("%s",ch) ;
if(ch[] == '=' || ch[] == '>'||ch[] == '<')
{
if(ch[] == '=')
yun = ;
else if(ch[] == '>' && ch[] == '=' )
yun = ;
else if(ch[] == '<' && ch[] == '=')
yun = ;
else if(ch[] == '>')
yun = ;
else if(ch[] == '<')
yun = ;
break ;
}
if(ch[] != '+')
sum += mp[ch] ;
}
scanf("%d",&x) ;
x *= ;
// printf("%d %d\n",sum,x) ;
if(yun == )
{
if(sum > x)
printf("Guess #%d was correct.\n",i) ;
else printf("Guess #%d was incorrect.\n",i) ;
}
if(yun == )
{
if(sum < x)
printf("Guess #%d was correct.\n",i) ;
else printf("Guess #%d was incorrect.\n",i) ;
}
if(yun == )
{
if(sum == x)
printf("Guess #%d was correct.\n",i) ;
else printf("Guess #%d was incorrect.\n",i) ;
}
if(yun == )
{
if(sum >= x)
printf("Guess #%d was correct.\n",i) ;
else printf("Guess #%d was incorrect.\n",i) ;
}
if(yun == )
{
if(sum <= x)
printf("Guess #%d was correct.\n",i) ;
else printf("Guess #%d was incorrect.\n",i) ;
}
}
return ;
}
HDU 2986 Ballot evaluation(精度问题)的更多相关文章
- hdu 2986 Ballot evaluation (模拟)
题目 上次比赛的题目,好长时间了. 这几天感冒了很难受, 直到现在才整理, 上次比赛的时候,出了各种错误, ,,,样例都没过,题目读的也很差,今天做的时候, 看了一下网上的,发现一个代码特别简洁, ...
- hdu 2986 Ballot evaluation (Simulation)
Problem - 2986 之前在华工赛见过的一道简单的模拟,用map轻松干掉.为了精确,要全程用整型比较.轻松1y~ 代码如下: #include <cstdio> #include ...
- Ballot evaluation
http://acm.hdu.edu.cn/showproblem.php?pid=2986 题意很简单,主要是要处理精度,最手残的是把单词拼写错了... #include <stdio.h&g ...
- hdu 6288(二分法加精度处理问题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6288 题意:给出a,b,k,n可满足(n^a)*(⌈log2n⌉)^b<=k ,求最大的n值三个 ...
- HDU 5705 Clock (精度控制,暴力)
题意:给定一个开始时间和一个角度,问你下一个时刻时针和分针形成这个角度是几点. 析:反正数量很小,就可以考虑暴力了,从第一秒开始暴力,直到那个角度即可,不会超时的,数目很少,不过要注意精度. 代码如下 ...
- hdu.. 基础二分的精度问题
#include<stdio.h>#include<iostream>using namespace std;double f(double x){ return 8*x*x* ...
- hdu 1969 pie 卡精度的二分
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU 4493 Tutor(精度处理)
题目 #include<stdio.h> int main() { int t; double a,s; scanf("%d",&t); while(t--) ...
- HDU 1007 Quoit Design(二分+浮点数精度控制)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
随机推荐
- MySQL之事务处理、存储过程
事务处理 动作 开始事务:start transaction 提交事务:commit 回滚事务:rollback 设置自动提交:set autocommit 1 | 0 autoCommit系统默认是 ...
- scala学习笔记:理解函数
定义一个函数: scala> def foo(x:Int)=x*2 foo: (x: Int)Int 可以采用匿名参数: scala> def foo:((Int)=>Int) = ...
- asp搜索两个以上的词的原理
通常会在许多网站上进行搜索一些内容,要输入两个或两个以上的词,它的原理是这样的: 假设在搜索框search中输入:“asp php” 先得到输入框中的内容:search=request("s ...
- SQL Server2008数据库自动备份步骤
一, 在电脑开始菜单中选择“SQL Server Management Studio”双击.在出现的界面中点击“连接”按钮. 二, 在出现的“ Microsoft SQL Server Manag ...
- intellij idea社区版 & maven & git & tomcat/jetty 的struts2项目的搭建
1.新建一个project,并在project下新建一个maven module.
- Java实战之04JavaWeb-08文件上传与下载
一.文件上传 1.文件上传的实质是什么 文件的拷贝,文件从客户端拷贝服务器端 2.文件上传的工作 (1)客户端怎样将本地文件输出去? 1)文件上传的表单项 <input type=”file”& ...
- java 中hashcode和equals 总结
一.概述 在Java中hashCode的实现总是伴随着equals,他们是紧密配合的,你要是自己设计了其中一个,就要设计另外一个.当然在多数情况下,这两个方法是不用我们考虑的,直 ...
- CENTOS7 使用网络管理器配置静态IP地址
CENTOS7 的网络配置和CENTOS6有些不同. 如果你想要使用网络管理器来管理该接口,你可以使用nmtui(网络管理器文本用户界面),它提供了在终端环境中配置配置网络管理器的方式. 在使用nmt ...
- Stable Matching 稳定匹配 婚姻算法 shapley 算法
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4051286.html 稳定匹配问题:有N男N女,每个人对于异性都一个排名,先需要得到一种稳 ...
- debian 学习记录-2 -账户 -关机
linux考虑系统安全设定了root账号和user账号 权限较低的user账号下,连关机命令都执行不了…… 用户切换... 用户切换1 命令su(在user账号下,即可开启root账号模式) 用户切换 ...