A - Elections

A - Elections

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

SubmitStatusPracticeCodeForces 570A

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 ≤ 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 Input

Input

3 31 2 32 3 11 2 1

Output

2

Input

3 410 10 35 1 62 2 21 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 }
时间: 2024-12-28 10:42:16

A - Elections的相关文章

[Codeforces 258B &amp; 259 D]Little Elephant and Elections 数位dp+dfs

http://codeforces.com/problemset/problem/258/B 题目大意: 说七个party选择数字(各不相同) 而规定的小象的party选择的数字之中所拥有的数字4和7的个数要比其他六个party拥有的个数之和还要严格多,询问方案数. 如m=7时其余的随意选择至少会拥有一个4或7,与题意矛盾,故方案数为0 m=8时,7 1 2 3 5 6 8是一种合法方案 思路: 由于小象的party选到的数字所含4和7的个数至多和m的位数一样多,则枚举小象的party所含4和7

UVA 11748 - Rigging Elections(dfs)

UVA 11748 - Rigging Elections 题目链接 题意:n个人选举,给出m个人的投票人对于每个人的优先级,现在你想让第c个人赢,问能不能 思路:对于两个人上场,如果a能赢b,就建一条a->b的边,然后问题其实就变成能否以c为根节点是一棵树,直接dfs一遍即可 代码: #include <cstdio> #include <cstring> #include <vector> using namespace std; const int N =

CodeForces 258B Little Elephant and Elections 数位DP

前面先用数位DP预处理,然后暴力计算组合方式即可. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostream> #include <map> #include <cstdlib> #include

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 un

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections(优先队列)

Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate wou

CodeForces - 369C - Valera and Elections

369C - Valera and Elections 思路:dfs,对于搜索到的每个节点,看他后面有没有需要修的路,如果没有,那么这个节点就是答案. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int N=1e5+5; vector<int>g[N]; vector<int>edge[N]; vector<int&

Little Elephant and Elections小象选举

在我正看着roll神的博客的时候发现了自己的错误 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostream> #include <map> #include <cstdlib> #include &

Codeforces 458C Elections 贿赂选票抢主席! 线段树

题目链接:点击打开链接 题意: 给定n张选票,每张选票有2个参数,第一个参数表示这张选票选的人 第二个参数表示如果让这张选票改为选0号 的花费 问:使得0号的选票是最高的(不能有和0号相同)的最小花费 枚举0号的最终选票 那么已知0号最终选票,则有些人选票比0号大的,那些票都要买下来. 如果买完了还是达不到 最终选票,就从所有剩下的选票里找前k小的. 用线段树求前k小的数的和,然后_(:зゝ∠)_就可以了 #include<iostream> #include<cstdio> #i

Codeforces Round #216 (Div. 2)---C. Valera and Elections

The city Valera lives in is going to hold elections to the city Parliament. The city has n districts and n?-?1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in