Codeforces 570 A. Elections

7634 단어
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의 선수에 대한 표수를 데이터[i][j]로 나눈다. 선거는 두 번으로 나뉜다. 첫 번째는 도시마다 이 도시에서 가장 많은 표를 얻은 선수를 뽑아 승리자가 된다. 만약에 표수가 같으면 번호가 가장 적은 선수를 선택한 다음에 2라운드에서 이 사람들 중에서 각 도시에서 가장 많은 승리를 거둔 선수를 최종 승리자로 선택하고 횟수가 같으면 번호가 가장 작은 선수를 선택한다.
직접 부호:
/* 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 **/

좋은 웹페이지 즐겨찾기