hdu 2986 Ballot evaluation (Simulation)
之前在华工赛见过的一道简单的模拟,用map轻松干掉。为了精确,要全程用整型比较。轻松1y~
代码如下:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <map> using namespace std; map<string, int> val; int con(char *str) {
int a, b;
sscanf(str, "%d.%d", &a, &b);
return a * + b;
} bool check(int a, int b, char *p) {
if (!strcmp(p, "=")) return a == b;
if (!strcmp(p, "<=")) return a <= b;
if (!strcmp(p, ">=")) return a >= b;
if (!strcmp(p, "<")) return a < b;
if (!strcmp(p, ">")) return a > b;
return false;
} int main() {
int n, m;
char buf[][];
while (cin >> n >> m) {
for (int i = ; i < n; i++) {
for (int i = ; i < ; i++) cin >> buf[i];
val[buf[]] = con(buf[]);
}
for (int cas = ; cas <= m; cas++) {
int sum = ;
while (true) {
cin >> buf[];
sum += val[buf[]];
cin >> buf[];
if (buf[][] != '+') break;
}
int x;
cin >> x;
cout << "Guess #" << cas << " was " << (check(sum, x * , buf[]) ? "correct." : "incorrect.") << endl;
}
}
return ;
}
——written by Lyon
hdu 2986 Ballot evaluation (Simulation)的更多相关文章
- hdu 2986 Ballot evaluation (模拟)
题目 上次比赛的题目,好长时间了. 这几天感冒了很难受, 直到现在才整理, 上次比赛的时候,出了各种错误, ,,,样例都没过,题目读的也很差,今天做的时候, 看了一下网上的,发现一个代码特别简洁, ...
- HDU 2986 Ballot evaluation(精度问题)
点我看题目 题意 : 给你n个人名,每个名后边跟着一个数,然后m个式子,判断是否正确. 思路 :算是一个模拟吧,但是要注意浮点数容易丢失精度,所以要好好处理精度,不知道多少人死在精度上,不过我实在是不 ...
- Ballot evaluation
http://acm.hdu.edu.cn/showproblem.php?pid=2986 题意很简单,主要是要处理精度,最手残的是把单词拼写错了... #include <stdio.h&g ...
- hdu 4973 A simple simulation problem. (线段树)
题目链接 题意: 给定n长的序列 m个操作 序列默认为 1, 2, 3···n 操作1:D [l,r] 把[l,r]区间增长 :( 1,2,3,4 进行 D [1,3]变成 1,1,2,2,3,3,4 ...
- hdu 4656 Evaluation [任意模数fft trick]
hdu 4656 Evaluation 题意:给出\(n,b,c,d,f(x) = \sum_{i=1}^{n-1} a_ix^i\),求\(f(b\cdot c^{2k}+d):0\le k < ...
- hdu 4190 Distributing Ballot Boxes(贪心+二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/1000 ...
- hdu 4190 Distributing Ballot Boxes 二分
Distributing Ballot Boxes Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- hdu 1057 (simulation, use sentinel to avoid boudary testing, use swap trick to avoid extra copy.) 分类: hdoj 2015-06-19 11:58 25人阅读 评论(0) 收藏
use sentinel to avoid boudary testing, use swap trick to avoid extra copy. original version #include ...
- HDU 4656 Evaluation(MTT)
题意 \(x_k=bc^{2k}+d\) \(\displaystyle F(x)=\sum_{i=0}^{n-1}a_ix^i\) 给定 \(\{a\},b,c,d,n\) ,求 \(F(x_0), ...
随机推荐
- 阿里云Global Connection亮相MWC 2019,做企业全球化开路先锋
上周在巴塞罗那举行的MWC 2019世界移动通信大会上,阿里云发布了包含Global Connection解决方案在内的7款重量级产品和解决方案,为全球企业提供了基于阿里云的智能化企业数字转型思路.G ...
- 【python之路19】文件操作
一.打开文件 文件句柄 = open('文件路径', '模式') 打开文件时,需要指定文件路径和以何等方式打开文件,打开后,即可获取该文件句柄,日后通过此文件句柄对该文件操作. 打开文件的模式有: r ...
- Handling Missing Values
1) A Simple Option: Drop Columns with Missing Values 如果这些列具有有用信息(在未丢失的位置),则在删除列时,模型将失去对此信息的访问权限. 此外, ...
- GCC/GDB学习
GCC学习 1.gcc是根据后缀名来区分文件的 .c : c语言源文件 .a : 目标文件构成的库文件 .C/.cc/.cxx : c++源文件 .h : 头文件 .i : 预处理过的C源文件 .ii ...
- python实现贝叶斯网络的概率推导(Probabilistic Inference)
写在前面 这是HIT2019人工智能实验三,由于时间紧张,代码没有进行任何优化,实验算法仅供参考. 实验要求 实现贝叶斯网络的概率推导(Probabilistic Inference) 具体实验指导书 ...
- 性能监控工具Munin
实际场景 公司产品需要观察Ubuntu主机性能,以衡量客户现场的产品是否能满足高频使用需求 选型 在比较了诸多工具之后,考虑时间成本因素,用了比较简单的Munin 安装步骤 1. apt-get in ...
- Idea下面无法识别web-inf下lib目录的子目录的jar包,只能直接放lib下面才能识别?
解决方案一: Ctrl+Alt+Shift+s打开projuect Structure-->Livraries-->➕-->java-->选择对应的lib目录即可! 解决方案二 ...
- 前端框架中 “类mixin” 模式的思考
"类 mixin" 指的是 Vue 中的 mixin,Regular 中的 implement 使用 Mixin 的目的 首先我们需要知道为什么会有 mixin 的存在? 为了扩展 ...
- iOS 自定义Tabbar实现push动画隐藏效果
http://wonderffee.github.io/blog/2013/08/07/hide-custom-tab-bar-with-animation-when-push/ 在之前的一篇文章(链 ...
- phpcms万能字段的使用方法
今天想做一个单选的字段,里面要使用别的字段,于是研究了一下万能字段!刚开始使用的时候,在网上,论坛里找了好久,没发现一个贴子有针对万能字段的使用说明,官方的例子里也只有一个调用字段本身值的变量 {FI ...