Codeforces Round #316 (Div. 2) A 水
1 second
256 megabytes
standard input
standard output
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 3
1 2 3
2 3 1
1 2 1
2
3 4
10 10 3
5 1 6
2 2 2
1 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.
题意:投票选州长 m个城市 n个候选人 给你n个候选人在每个城市的得票数 在当前城市获票最多的候选人获胜 当票数一样时 编号小的
候选人获胜 统计获得城市获胜最多的候选人作为州长 当出现获胜次数相同的情况下 输出编号最小的一名
题解: 水
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<algorithm>
#define ll __int64
#define mod 1e9+7
#define PI acos(-1.0)
using namespace std;
int n,m;
int exm;
int biao;
map<int,int> mp;
int main()
{
int ans=;
int maaa=;
scanf("%d %d",&n,&m);
mp.clear();
for(int i=;i<=m;i++)
{
int biao=;
int maxn=-;
for(int j=;j<=n;j++)
{
scanf("%d",&exm);
if(exm>maxn)
{
maxn=exm;
biao=j;
}
}
mp[biao]++;
if(mp[biao]>maaa||(mp[biao]==maaa&&biao<ans))
{
maaa=mp[biao];
ans=biao;
}
}
cout<<ans<<endl;
return ;
}
Codeforces Round #316 (Div. 2) A 水的更多相关文章
- Codeforces Round #365 (Div. 2) A 水
A. Mishka and Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Codeforces Round #316 (Div. 2) C. Replacement set
C. Replacement Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/proble ...
- Codeforces Codeforces Round #316 (Div. 2) C. Replacement 线段树
C. ReplacementTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem ...
- Codeforces Round #316 (Div. 2)
A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)
A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...
- Codeforces Round #408 (Div. 2)(A.水,B,模拟)
A. Buying A House time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #394 (Div. 2)A水 B暴力 C暴力 D二分 E dfs
A. Dasha and Stairs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #169 (Div. 2) A水 B C区间更新 D 思路
A. Lunch Rush time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #337 (Div. 2) A水
A. Pasha and Stick time limit per test 1 second memory limit per test 256 megabytes input standard i ...
随机推荐
- windows下安装win7虚拟机并安装oracle
一.win7虚拟机 与安装linux虚拟机没有什么不同,不同的是选择客户机操作系统.内存.磁盘容量,以及映像文件. 创建win7虚拟机步骤简化: 新建虚拟机-->>自定义-->> ...
- Angular 2 树节点的上下移动问题
最近在做一个树节点的上下移动然后实现排序的问题.直接看图: 实现已选查询条件的上下移动.结合了primeng 的picklist 组件. 下面是html代码 <p-tabPanel header ...
- 解决ndk编译lua时遇到 undefined reference to '__srget'的问题
今天用ndk r10d版本编译lua时,遇到几个错误,提示没有找到__srget 没有定义,于是看了国外的大神的解决方法, 是因为ndk在r10c之后的版本已经将getc函数屏蔽了,所以导致编译器找不 ...
- Load事件中控件Focus()无效解决办法
原因:Load窗体时,窗体未显示 解决:1.Focus()之前添加this.Show(); 2.在Shown事件中添加Focus()
- 《转载》ASP动态iframe
原文:[ASP.NET]关于iframe的两个技巧 最近在给朋友写个网站,虽然不大,但是也碰到了一些问题.这篇就为解决ASP.NET中关于IFRAME的两个很现实的问题提供解决方法.PS:呵呵,又做了 ...
- flask-bootstrap
pip install bootstarp 使用bower安装bootstrap的命令是: bash$ bower install bootstrap不过问题出在如何安装bower上. 官方网站上这样 ...
- nginx负载均衡集群(二)
nginx负载均衡配置实战 一.配置基于域名虚拟主机的web节点 web02和web01做同样的操作,nginx配置文件如下: [root@web01 conf]# cat nginx.conf wo ...
- DevOps - CI/CD - Jenkins
Jenkins 是一款流行的开源持续集成(Continuous Integration)工具,广泛用于项目开发,具有自动化构建.测试和部署等功能.本文以 CentOS7 环境为例,总结了 Jenkin ...
- nginx平滑升级的过程
1.开始之前首先查看当前的使用版本以及编译时的参数: [root@www ~]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.12.2 ...
- Hi3518EV300编译U-Boot和内核报错:loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed. Aborted (core dumped)
下载Hi3518EV300的SDK后编译内核和U-boot,发现爆出如下错误: scripts/kconfig/conf --silentoldconfig Kconfig Aborted (core ...