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 ...
随机推荐
- 使用Keil建立工程和烧录到89C52板上
又开始学习C51了,不清楚能坚持多久,之前学过一段时间,学完P1口就没再学了,之前学的都忘了. 1. 使用Keil 进行建立工程:打开Keil 4. 加载C文件进工程里面 然后展开"Sour ...
- [转载][jQuery] Cannot read property ‘msie’ of undefined错误的解决方法
参考 [jQuery] Cannot read property ‘msie’ of undefined错误的解决方法 ---------------------------------------- ...
- CSS3 过渡transition 认识
其实,我一直觉得自己对新知识是以一种抵触的情绪在学习的.因为我总是习惯于将事情想得很复杂,所以也错过了很多美好的东西. 以前觉得CSS3的知识应该是很难的,很难理解的.但是我发现我觉得知识点很难,是因 ...
- java中的拷贝文件FileChannel
以前用Java拷贝文件,只知道写byte数组循环拷贝,今天知道了可以用FileChannel进行拷贝,上代码: 下边是传统的byte数组拷贝方法 </pre><pre name=&q ...
- sql2008存储过程解密。
今天有一个同事在做一个项目的时候,因为现在公司不跟某一家公司合作.有一些sql的存储过程是加密,现在想打开那些存储过程来解密.故查看了一些资料终于解密成功.步骤如下: 1.需要开始DAC连接. 1.1 ...
- 用JQuery编写textarea,input,checkbox,select
今天学习怎样用JQuery编写一些小的代码,小小的试了一下编写一个textarea,代码如下: <!DOCTYPE HTML> <html lang="en"&g ...
- getScript 按需加载javascript
$('input:button:first').click(function(aaa) { $.getScript('new.js', function() { alert('Script loade ...
- JavaScript学习笔记(8)——JavaScript语法之运算符
一. 算术运算符: 运算符 描述 例子 结果 + 加 x=y+2 x=7 - 减 x=y-2 x=3 * 乘 x=y*2 x=10 / 除 x=y/2 x=2.5 % 求余数 (保留整数) x=y%2 ...
- JavaScript解析json
后台数据经常以json数据格式传回前台,解析当然首选JSON对象. JSON对象有两个方法,使用JSON.parse(str)可以将json字符串解析成js中的对象. var o = JSON.par ...
- 九度OJ 1500 出操队形 -- 动态规划(最长上升子序列)
题目地址:http://ac.jobdu.com/problem.php?pid=1500 题目描述: 在读高中的时候,每天早上学校都要组织全校的师生进行跑步来锻炼身体,每当出操令吹响时,大家就开始往 ...