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 ...
随机推荐
- JS完美运动框架
这套框架实现了多物体,任意值,链式运动,多值运动,基本满足常见的需求. /* 功能:完美运动框架,可以实现多物体,任意值,链式运动,多值运动 版本:V1.0 兼容性:Chrome,FF,IE8+ (o ...
- spark处理jsonFile
按照spark的说法,这里的jsonFile是特殊的文件: Note that the file that is offered as jsonFile is not a typical JSON f ...
- kettle Java Filter(表达式过滤)
- 对象创建型模式------Singleton(单例模式)
地址:http://blog.csdn.net/wuzhekai1985/article/details/6665869.仅供自己参考学习. 单例模式:保证一个类仅有一个实例,并提供一个访问它的全局节 ...
- Android更改桌面应用程序launcher的两种方式
http://blog.csdn.net/mdx20072419/article/details/9632779/ launcher,也就是android的桌面应用程序.下图是我正在使用的魅族手机的l ...
- (一)问候Spring4
第一节:Spring 简介 Spring 作者:Rod Johnson: 官方网站:http://spring.io/ 最新开发包及文档下载地址:http://repo.springsource.or ...
- getScript 按需加载javascript
$('input:button:first').click(function(aaa) { $.getScript('new.js', function() { alert('Script loade ...
- 12天学好C语言——记录我的C语言学习之路(Day 7)
12天学好C语言--记录我的C语言学习之路 Day 7: 昨天进行了一天的数组学习,今天大家可以先写几个昨天的程序热热身,回顾回顾,然后今天第一个新程序也是关于数组的,比较难,准备好就开始啦! //输 ...
- 懒人记录 Hadoop2.7.1 集群搭建过程
懒人记录 Hadoop2.7.1 集群搭建过程 2016-07-02 13:15:45 总结 除了配置hosts ,和免密码互连之外,先在一台机器上装好所有东西 配置好之后,拷贝虚拟机,配置hosts ...
- Mac或Linux中对Android抓包
转载说明 本篇文章可能已经更新,最新文章请转:http://www.sollyu.com/mac-or-linux-android-caught/ 说明 首先要到http://www.charlesp ...