Codeforces 570 A. Elections

click here ~~

                                           ***A. Elections***

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 numberthe index of the candidate who won the elections. The candidates are indexed starting from one.

题意:
给出n行m列,代表第i个城市对第j的选手的票数data[i][j],选举分为两次,第一次,每个城市选出这个城市得票最高的选手成为胜利者,如果票数一样,选编号最小的,然后第二轮,选择这些人里面在各个城市被选的胜利次数最多的选手作为最终胜利者,如果次数一样,选编号最小的。

直接上代码:

/*
Date : 2015-8-26 晚上
Author : ITAK

Motto :

今日的我要超越昨日的我,明日的我要胜过今日的我;
以创作出更好的代码为目标,不断地超越自己。
*/
#include <iostream>
#include <cstring>
using namespace std;
int data[105][105];
int ans[105];
int main()
{
    int m, n, j, i, ind;
    while(cin>>m>>n)
    {
        memset(ans, 0, sizeof(ans));
        for(i=0; i<n; i++)
        {
            int Max = -999;
            for(j=0; j<m; j++)
            {
                cin>>data[i][j];
                if(data[i][j] > Max)
                {
                     Max = data[i][j];
                     ind = j;
                }
            }
            ans[ind]++;
        }
        int Max = -9999;
        for(i=0; i<m; i++)
            if(ans[i] > Max)
            {
                Max = ans[i];
                ind = i;
            }
        cout<<ind+1<<endl;
    }
    return 0;
}
/**
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
**/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值