Content

有 \(n\) 名选手参加一个比赛,有 \(m\) 个人为他们投票。第 \(i\) 个人的投票情况用一个长度为 \(n\),并且仅包含 .X 两个字符的字符串,其中,如果第 \(j\) 位是 X,则第 \(i\) 个人将票投给了第 \(j\) 名选手,否则没有。规定每个投票者能且仅能将票投给一个人,否则都算无效票(即投的票数 \(\geqslant 2\) 或者 \(=0\))。请将每名选手按照他们所得到的票的比例排序(如果有两名选手得到的票的比例相同,在投票次序中先出现的那名选手排在前面),并输出他们的名字和得票比例,最后还要输出无效票所占的比例。

比例输出为百分数,\(\%\) 前面的部分四舍五入到 \(2\) 位小数。

数据范围:\(2\leqslant n\leqslant 10,1\leqslant m\leqslant 1000\)。

Solution

直接按照题意模拟就好,不过要注意四舍五入的问题。printf 的自动四舍五入有时候会出现 bug 导致 WA on test 19,所以需要自己手写一个函数来处理四舍五入。具体实现可以参考这里的代码。

Code

int n, m, in;
string tp;
struct user {
string name;
int val, id;
bool operator < (const user& cz) const {return val > cz.val || (val == cz.val && id < cz.id);}
}a[17]; inline void judge(string s) {
int len = s.size(), xnum = 0, xpl;
F(i, 0, len - 1) if(s[i] == 'X') xnum++, xpl = i + 1;
if(xnum != 1) {in++; return;}
a[xpl].val++;
}
inline double getans(int x) {
double ans = x * 1.0 / m, aa = ans * 10000;
return floor(aa + 0.5) / 100.0;
} int main() {
n = Rint, m = Rint;
F(i, 1, n) {
cin >> a[i].name;
a[i].id = i;
}
F(i, 1, m) {
cin >> tp;
judge(tp);
}
sort(a + 1, a + n + 1);
F(i, 1, n) {
cout << a[i].name << ' ';
double ans = getans(a[i].val);
printf("%.2lf%%\n", ans);
}
printf("Invalid %.2lf%%\n", getans(in));
return 0;
}

LuoguP7080 [NWRRC2013]Ballot Analyzing Device 题解的更多相关文章

  1. Codeforces Gym 100269B Ballot Analyzing Device 模拟题

    Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...

  2. HNU 12845 Ballot Analyzing Device

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12845&courseid=270 解题报告:有m个认给 ...

  3. Codeforces Gym 100269A Arrangement of Contest 水题

    Problem A. Arrangement of Contest 题目连接: http://codeforces.com/gym/100269/attachments Description Lit ...

  4. 2015 Multi-University Training Contest 1 题解&&总结

    ---------- HDU 5288 OO’s Sequence 题意 给定一个数列(长度<$10^5$),求有多少区间[l,r],且区间内有多少数,满足区间内其它数不是他的约数. 数的范围$ ...

  5. Analyzing UI Performance with Systrace 使用systrace工具分析ui性能

    While developing your application, you should check that user interactions are buttery smooth, runni ...

  6. Xcode 9 Analyzing Crash Reports

    Analyzing Crash Reports After you distribute your app for testing by using TestFlight or after you m ...

  7. HDU 5294 Tricks Device 网络流 最短路

    Tricks Device 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5294 Description Innocent Wu follows D ...

  8. Kuangbin 带你飞专题十一 网络流题解 及模版 及上下界网络流等问题

    首先是几份模版 最大流:虽然EK很慢但是优势就是短.求最小割的时候可以根据增广时的a数组来判断哪些边是割边.然而SAP的最大流版我只会套版,并不知道该如何找到这个割边.在尝试的时候发现了一些问题.所以 ...

  9. Android 性能优化(25)*性能工具之「Systrace」Analyzing UI Performance with Systrace:用Systrace得到ui性能报告

    Analyzing UI Performance with Systrace In this document Overview 简介 Generating a Trace  生成Systrace文件 ...

随机推荐

  1. 洛谷 P4749 - [CERC2017]Kitchen Knobs(差分转换+dp,思维题)

    题面传送门 一道挺有意思的思维题. 首先有一个 obvious 的结论,就是对于每个炉子,要么转到哪里都符合条件,要么存在唯一的最大值.对于转到哪儿都符合条件的炉子我们 duck 不必考虑它,故我们只 ...

  2. 体积与边精确积分DGM方法

    Triangular DGM 1. Basis functions decomposing the domain \(\Omega\) into \(N_e\) conforming non-over ...

  3. 【豆科基因组】大豆适应性位点GWAS分析 [转载]

    目录 材料与方法 结果分析 本文利用99085个高质量SNP 通过STRUCTURE,PCA和neighbour-joining tree的群体结构分析将地方品种分为三个亚群,这些亚群表现出地理上的遗 ...

  4. MetaboAnalyst的多组学分析

    MetaboAnalyst是做代谢的R包,功能十分强大.也开发了web版本,代谢组学的分析这里不介绍,主要讲讲它开发的多组学分析的相关内容. 既然是做代谢的工具,即使是增加了多组学内容,肯定也是以代谢 ...

  5. C语言小练习 微型学生管理系统

    很简陋,没有做输入校验,以写出来为第一目的,中间出了不少问题,尤其是结构体内字符串赋值的时候(理解不透彻),字符串比较用strcmp不能直接==判定,逻辑也很重要,不然会出现莫名其妙的问题. 涉及知识 ...

  6. .Net 下高性能分表分库组件-连接模式原理

    ShardingCore ShardingCore 一款ef-core下高性能.轻量级针对分表分库读写分离的解决方案,具有零依赖.零学习成本.零业务代码入侵. Github Source Code 助 ...

  7. A Child's History of England.23

    King William, fearing he might lose his conquest, came back, and tried to pacify the London people b ...

  8. SQLite is 35% Faster Than The Filesystem

    比方说你要在C++/PHP里实现一个函数Image get_image(string id),不同的图片有1万张(用户头像),你可以把它们存在一个目录/文件夹里,然后fopen()再fread. 你也 ...

  9. A Child's History of England.44

    At this period of his reign, when his troubles seemed so few and his prospects so bright, those dome ...

  10. day22面向对象编程思想

    day22面向对象编程思想 1.面向过程 面向过程: 核心是"过程"二字 过程的终极奥义就是将程序流程化 过程是"流水线",用来分步骤解决问题的 面向对象: 核 ...