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 ≤ 10^9) 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 10^9.

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.

看上面的解释也应该知道怎么做了吧

#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x7fffffff
#define INFL 0x7fffffffffffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int q[1000];
struct P
{
int num;
int adress;
}L[100000];
bool cmd(P x,P y)
{
if(x.num==y.num)
{
return x.adress<y.adress;
}
else
return x.num>y.num;
}
int main()
{
int n,m;
int ans;
int sum=-inf;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
cin>>L[j].num;
L[j].adress=j;
}
sort(L+1,L+n+1,cmd);
// cout<<L[1].adress;
q[L[1].adress]++;
}
// sort(q+1,q+1+n);
for(int i=1;i<=n;i++)
{
sum=max(q[i],sum);
//cout<<q[i]<<endl;
}
for(int i=1;i<=n;i++)
{
if(q[i]==sum)
{
cout<<i<<endl;
break;
}
//sum=max(q[i],sum);
//cout<<q[i]<<endl;
}
// cout<<sum<<endl;
// cout<<q[n]<<endl;
return 0;
}

  

Codeforces Round #316 (Div. 2) A的更多相关文章

  1. Codeforces Codeforces Round #316 (Div. 2) C. Replacement set

    C. Replacement Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/proble ...

  2. Codeforces Codeforces Round #316 (Div. 2) C. Replacement 线段树

    C. ReplacementTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem ...

  3. Codeforces Round #316 (Div. 2) C. Replacement

    题意:给定一个字符串,里面有各种小写字母和' . ' ,无论是什么字母,都是一样的,假设遇到' . . ' ,就要合并成一个' .',有m个询问,每次都在字符串某个位置上将原来的字符改成题目给的字符, ...

  4. Codeforces Round #316 (Div. 2) B. Simple Game

    思路:把n分成[1,n/2],[n/2+1,n],假设m在左区间.a=m+1,假设m在右区间,a=m-1.可是我居然忘了处理1,1这个特殊数据.被人hack了. 总结:下次一定要注意了,提交前一定要看 ...

  5. Codeforces Round #316 (Div. 2) D计算在一棵子树内某高度的节点

    题:https://codeforces.com/contest/570/problem/D 题意:给定一个以11为根的n个节点的树,每个点上有一个字母(a~z),每个点的深度定义为该节点到11号节点 ...

  6. Codeforces Round #316 (Div. 2) D. Tree Requests dfs序

    D. Tree Requests time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  7. Codeforces Round #316 (Div. 2)

    A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  8. Codeforces Round #316 (Div. 2) D、E

    Problem D: 题意:给定一棵n个点树,每个点有一个字母,有m个询问,每次询问某个节点x的子树中所有深度为k的点能否组成一个回文串 分析:一堆点能组成回文串当且仅当数量为奇数的字母不多于1个,显 ...

  9. Codeforces Round #316 (Div. 2C) 570C Replacement

    题目:Click here 题意:看一下题目下面的Note就会明白的. 分析:一开始想的麻烦了,用了树状数组(第一次用)优化,可惜没用. 直接判断: #include <bits/stdc++. ...

  10. Codeforces Round #316 (Div. 2B) 570B Simple Game 贪心

    题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int IN ...

随机推荐

  1. windows python-mysql 安装

    https://www.cnblogs.com/gbx-bo/p/5993190.html

  2. Using JConsole

    Using JConsole 转自 https://docs.oracle.com/javase/8/docs/technotes/guides/management/jconsole.html Th ...

  3. [codeforces126B]Password

    解题关键:KMP算法中NEXT数组的理解. #include<bits/stdc++.h> #define maxn 1000006 using namespace std; typede ...

  4. 关于const指针的误解

    转自 http://blog.csdn.net/yingxunren/article/details/3968800 const char*, char const*, char*const的区别问题 ...

  5. p3172 选数

    传送门 分析 对这个$f(k)$整除分块,用杜教筛搞出$\mu$的部分然后另一部分快速幂即可 代码 #include<iostream> #include<cstdio> #i ...

  6. 100085G GCD Guessing Game

    传送门 题目大意 给定一个数N,现在又一个数x,在1~N之间,现在每次可以猜一个数a,返回gcd(x,a),问说最少猜几次可以确定x. 分析 这个题应该可以算是贪心,但是没人知道这样为啥是对的(雾), ...

  7. Swing窗口Linux下不支持最大化问题

    Swing窗口Linux下不支持最大化问题 摘自:https://www.linuxidc.com/Linux/2009-06/20519.htm [日期:2009-06-17] 来源:www.qua ...

  8. 原型模式--其实就是考察clone

    http://blog.csdn.net/zhengzhb/article/details/7393528

  9. java全栈day33--html

    本天要完成6个任务,并且布局静态页面(首页)详细分为六个部分  如下 网站信息页面案例(字体标签.排版标签) 网站图片信息页面案例(图片标签) 网站友情链接页面案例(列表标签) 网站首页案例(表格标签 ...

  10. SQLite操作

    创建有主键的表: create table test (pkey varchar(16) primary key, value varchar(10)); 创建有复合(即key由多个字段联合组成)主键 ...