Codeforces Round #316(Div.2) 570A Elections(아날로그)
3525 단어 모방하다Codeforces
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 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.
앞으로 B부터 해야 돼요. A를 하고 나면 B가 머리가 안 따라와요.
m개 도시 n개의 선거자, 점수가 높으면 해당 사람은 선거에 성공한 사람이고 같은 선거구의 번호가 비교적 작다.
AC 코드:
#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int MAXN = 105;
typedef long long ll;
int n, m;
struct node
{
/* data */
ll x;
int flag;
}a[MAXN];
struct node2
{
/* data */
ll num;
int flag;
}b[MAXN];
bool cmp1(node a, node b)
{
if(a.x == b.x) return a.flag < b.flag;
return a.x > b.x;
}
bool cmp2(node2 a, node2 b)
{
if(a.num == b.num) return a.flag < b.flag;
return a.num > b.num;
}
int main(int argc, char const *argv[])
{
for(int i = 1; i < MAXN; ++i)
b[i].flag = i;
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; ++i) {
for(int j = 1; j <= n; ++j) {
scanf("%lld", &a[j].x);
a[j].flag = j;
}
sort(a + 1, a + n + 1, cmp1);
b[a[1].flag].num++;
}
sort(b + 1, b + n + 1, cmp2);
printf("%d
", b[1].flag);
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[CF 817F] MEX Queries(라인 트리)길이 1018 1018의 0101 서열을 유지하고 도자기 구간에 값을 부여하고 구간에서 반전을 취하며 첫 번째 0의 위치를 조회해야 한다. 이산화 후 라인 트리로 역표기, 부치표기를 유지하면 됩니다....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.