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 Linux下VNC Server远程桌面配置详解
一.安装相应桌面环境与vnc服务端和客户端: # yum groupinstall "GNOME Desktop Environment"(CentOS 5.x安装GNOME桌面环 ...
- 用友NC V6.3打造集团企业高效信息平台
近年来,随着互联网快速发展,信息化管理的应用也越来越普及,信息化建设已经深入到很多企业的核心业务,而且为了确保业务稳定.可靠并快速.有效地 开展,企业经常会运用多个信息系统进行辅助支撑,但是,许多企业 ...
- Lua - 基础语法
Hello World 交互式编程 Lua 交互式编程模式可以通过命令 lua -i 或 lua 来启用: [huey@huey-K42JE lua]$ lua Lua 5.1.4 Copyright ...
- Centos7最小化安装后(minimal)安装图形界面
centos7下载地址:http://mirrors.cqu.edu.cn/CentOS/7/isos/x86_64/CentOS-7-x86_64-Minimal-1511.iso 下载后用vmwa ...
- WebClient.UploadValues Post中文乱码的解决方法
//using (System.Net.WebClient wc = new System.Net.WebClient()) //{ // wc.Encoding = Encoding.GetEnco ...
- 打包C#程序
开源中国. 今天来使用VS2010对C#程序进行打包发布. 我们有一个C#程序.程序很简单,我们需要对它进行发布. Contents 步骤: 建立一个安装项目.我们得到了一个Setup1项目. 在应用 ...
- 【html】【20】高级篇--轮播图[聚焦]
下载: http://sc.chinaz.com/jiaoben/151204445580.htm 效果: html <!doctype html> <html> <he ...
- iOS 分类思想(2)
/******************* NSString+NumCount.h文件 ******************************/ #import <Foundation/Fo ...
- ASP.NET DataList嵌套实现评论效果
问题: Datalist1显示say这个表的数据 然后想在Datalist1中嵌套一个Datalist2用于显示对应的评论表2的 sayID对应表1的id,若表2中找不到对应sayId则在对应的Dat ...
- Unity3D--学习太空射击游戏制作(三)
步骤四:创建敌人 创建敌人的方式与创建主角类似,不过敌人的行为需要由计算机来控制,它将从上方迎着主角缓慢飞出来,并左右来回移动: 01:创建Enemy.cs脚本,添加代码: using UnityEn ...