您的位置:首页 > 其它

Codeforces Round #316 (Div. 2)A. Elections

2015-08-14 13:48 316 查看
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.

Input

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.

Output

Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.

Sample test(s)

input
3 3
1 2 3
2 3 1
1 2 1


output
2


input
3 4
10 10 3
5 1 6
2 2 2
1 5 7


output
1


Note

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.

题意:有n个人在m个城市里进行选举,每个城市里获得票数最多的那个人就会增加一颗星,如果有多个人都是最多的,那么就给号码(下标)最小的那个人加一个星。求获得星标最多的那个人编号,同样的,如果多个人都是最多的,那么输出编号最小的那个。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int num[200],i,j,max1,max2,index1,index2,temp;
int n,m;
cin>>n>>m;
memset(num,0,sizeof(num));
max2=-1;index2=-1;
for(i=1;i<=m;i++){
max1=-1;index1=-1;
for(j=1;j<=n;j++){
scanf("%d",&temp);
if(temp>max1){
index1=j;
max1=temp;
}
}
num[index1]++;
if(num[index1]>max2 || (num[index1]==max2 && index1<index2)){
max2=num[index1];
index2=index1;
}
}
printf("%d\n",index2);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: