码迷,mamicode.com
首页 > 其他好文 > 详细

A - Elections

时间:2016-05-07 00:46:08      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:

                                                                                  A - Elections
 
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 nm (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 ≤ n1 ≤ i ≤ m0 ≤ 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 Input

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
这一题,容我再去看一遍题意..
好了,言归正传:
老规矩,先上题意:就是国家选举,这个国家有着奇葩的选举制度,共有n个候选人和m个城市,每个候选人在每个城市获得的选票列成一行,所以共有n行。所有城市获得的选票相加和最大的候选人获胜,那么,当有两个以上候选人所得选票都是最大值怎么办呢,奇葩就奇葩在这里!当这种情况发生的时候,他们就会选输入顺序最靠前的候选人当选总统。。
好了,下面是AC代码:
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7 const int MAX=150;
 8 const int INF=1<<30;//表示正无穷 
 9 int n,m;
10 int main(){
11     while(scanf("%d %d",&m,&n)!=EOF){
12         int a[MAX][MAX];
13         int b[MAX];//储存所有候选人的选票和 
14         int k;
15         memset(b,0,sizeof(b));
16         for(int i=1;i<=n;i++){
17             for(int j=1;j<=m;j++){
18                 scanf("%d",&a[i][j]);
19             }
20         }
21         for(int i=1;i<=n;i++){
22             k=1;
23             for(int j=1;j<=m;j++)
24         {
25             if(a[i][j]>a[i][k])
26             {
27                 k=j;
28             }
29             
30         }
31         ++b[k];
32         }
33         k=1;
34         for(int i=1;i<MAX;i++)
35     {
36         if(b[i]>b[k])//找出最靠前的最大值 
37         {
38             k=i;
39         }
40     }
41     printf("%d\n",k);
42 }
43     
44     return 0;
45 }

 

A - Elections

标签:

原文地址:http://www.cnblogs.com/Kiven5197/p/5467440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!