A. Elections(Codeforces Round #316 (Div. 2) 简单题)

A. Elections

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The country of Byalechinsk is running elections involvingncandidates. The country consists ofmcities. 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 integersn,m(1≤n,m≤100) — the number of candidates and of cities, respectively.

Each of the nextmlines containsnnon-negative integers, thej-th number in thei-th lineaij(1≤j≤n,1≤i≤m,0≤aij≤109) denotes the number of votes for candidatejin cityi.

It is guaranteed that the total number of people in all the cities does not exceed109.

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 31 2 32 3 11 2 1

output

2

input

3 410 10 35 1 62 2 21 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个城市,,现在要从m个城市中的选票中选取得票最高的候选人,如果在一个城市中两个候选人得到的票数是相同的且是最高的,那么标号小的候选人获胜,如果m个城市中选出的候选人的中有票数最高且相同的,依旧选标号最小的。

点击打开链接

#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<queue>#include<stack>#include<vector>#include<map>using namespace std;int v[110];int n,m,k,sum,x;int main(){while(scanf("%d %d",&n,&m)!=EOF){memset(v,0,sizeof(v));for(int i=0;i<m;i++){k=1;sum=-1;for(int i=1;i<=n;i++){scanf("%d",&x);if(sum<x){sum=x;k=i;}}v[k]++;}int Max=0;int ans=1;for(int i=1;i<=n;i++){if(v[i]>Max){Max=v[i];ans=i;}}printf("%d\n",ans);}return 0;}

版权声明:本文为博主原创文章,如有特殊需要请与博主联系 QQ : 793977586。

有一种缘,放手后成为风景,有一颗心,坚持中方现真诚。

A. Elections(Codeforces Round #316 (Div. 2) 简单题)

相关文章:

你感兴趣的文章:

标签云: