Codeforces Round #316 (Div. 2)570A Elections(模拟)
来源:互联网 发布:淘宝搜索引擎工作流程 编辑:程序博客网 时间:2024/05/21 06:33
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively.
Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i.
It is guaranteed that the total number of people in all the cities does not exceed 109.
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
3 31 2 32 3 11 2 1
2
3 410 10 35 1 62 2 21 5 7
1
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
以后得先做B,做完A想一会B脑子就跟不上了
m个城市n个选举者,得分高则该人为成功选举的人,得分相同选区编号较小的。
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;const int MAXN = 105;typedef long long ll;int n, m;struct node{/* data */ll x;int flag;}a[MAXN];struct node2{/* data */ll num;int flag;}b[MAXN];bool cmp1(node a, node b){if(a.x == b.x) return a.flag < b.flag;return a.x > b.x;}bool cmp2(node2 a, node2 b){if(a.num == b.num) return a.flag < b.flag;return a.num > b.num;}int main(int argc, char const *argv[]){for(int i = 1; i < MAXN; ++i) b[i].flag = i;scanf("%d%d", &n, &m);for(int i = 1; i <= m; ++i) {for(int j = 1; j <= n; ++j) {scanf("%lld", &a[j].x);a[j].flag = j;}sort(a + 1, a + n + 1, cmp1);b[a[1].flag].num++;}sort(b + 1, b + n + 1, cmp2);printf("%d\n", b[1].flag);return 0;}
- Codeforces Round #316 (Div. 2)570A Elections(模拟)
- Codeforces Round #316 (Div. 2) A. Elections
- Codeforces Round #316 (Div. 2) A. Elections
- Codeforces Round #316 (Div. 2)A. Elections
- Codeforces Round #316 (Div. 2) A. Elections
- 570A.Elections Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)-A. Elections-模拟水题22
- A. Elections(Codeforces Round #316 (Div. 2) 简单题)
- A. Elections-----------(Codeforces Round #316 (Div. 2))
- Codeforces Round #318 (Div. 2) A - Bear and Elections 模拟暴力枚举
- Codeforces Round #318 (Div. 2) A. Bear and Elections
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections(优先队列)
- Codeforces Round #297 (Div. 2) A(模拟)
- Codeforces Round #340 (Div. 2)(A) 模拟
- 在青岛穷游打的cf codeforces Round #318 (Div. 2) A.Bear and Elections
- Codeforces #318 (Div. 2 A. Bear and Elections (模拟/优先队列
- Codeforces Round #216 (Div. 2) C. Valera and Elections
- Codeforces Round #216 (Div. 2)---C. Valera and Elections
- 腾讯面试专场
- 面试题五: 从尾到头打印链表
- POJ 2115 for求循环次数-数论-(同余方程+扩展欧几里得算法)
- 黑马程序员Java笔记——集合篇(一)
- OC_FileManager_文件内外操作
- Codeforces Round #316 (Div. 2)570A Elections(模拟)
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2) C. Replacement 找规律 或 线段树
- Codeforces Round #316 (Div. 2)570B Simple Game(脑洞)
- Codeforces Round #316 (Div. 2)-C. Replacement
- cocos2dx 3.3 scrollView lua 版本幻灯片效果
- Codeforces Round #316 (Div. 2) -B-Simple Game-水题
- Codeforces Round #316 (Div. 2)-A. Elections-模拟水题22
- 算法题:科学计数法