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 ...
随机推荐
- centos_Error: Protected multilib versions_解决方法
在yum命令后面加入忽略参数:--setopt=protected_multilib=false you can also use --setopt=protected_multilib=false ...
- PHP 简易读取文件目录下的文件,生成css spirte图片
因为个人不是对PS熟悉,不清楚如何在PS中生成一张横向有序的spirte图片,使用了"css sprite V4.3"版本,生成的图片会出现压缩图片大小的情况,本想修改原作者开发的 ...
- SharePoint2013 SharePoint-Hosted 模式 分页方法
/**分页js插件 var ListPager = new listPaging(); 先调用start方法加载上下文 然后调用dataLoad方法查询第一页数据 需要设置几个属性值 ListPage ...
- VS2012无法创建项目:未找到与约束……匹配的导出
故障情况:7月10号后用VS2012创建项目时,弹出如下对话框,无法创建新项目: 而后经网络搜索确定是7月10号更新了系统补丁后造成的 解决方案: 1.卸载这两个补丁后重启电脑: 2.到http:// ...
- apache http server 多线程模式
一般apache采用prefork和worker机制,通过apachectl -l命令查看默认使用的prefork机制.需要修改prefork策略 那么需要做如下修改: 1,/usr/local/ap ...
- Centos7最小化安装后(minimal)安装图形界面
centos7下载地址:http://mirrors.cqu.edu.cn/CentOS/7/isos/x86_64/CentOS-7-x86_64-Minimal-1511.iso 下载后用vmwa ...
- FFMPEG高级编程第一篇:环境搭建及编译
前段时间在翻看电脑里面资料时,发现了以前做的在嵌入式硬件上面运行以ffmepg为基础,以嵌入式硬件解码的多媒体播放工作,发现都快忘记完了.今日得闲整理温习了一下ffmpeg在嵌入式上的运用,这里给大家 ...
- 第三篇、FMDB使用
简介: FMDB是基于SQlite3的封装一个第三方的OC库,操作起来更加简单,性能比Coredata更加高. 1.创建sqlite文件 2.导入FMDB头文件 3.创建数据库表table 4.编写s ...
- 信息收集->DNS分析->dnsdict6
如何获取域名的IPV4/IPV6地址之dnsdict6的使用 dnsdict6是一个用于获取网站信息的工具.dnsdict6可以扫描网站并显示有多少域或者子域,也可以扫描ipv6/ipv4地址.dns ...
- 用EPPlus导入导出数据到excel
项目上中要用到将数据库中所有表导出为Excel,以及将Excel数据导入数据库中的操作,使用EPPlus组件,编写以下两个函数. using OfficeOpenXml;using OfficeOpe ...