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;
}

  

最新文章

  1. 一个微软的DDD架构图
  2. Oracle如何导出sys用户下的系统表
  3. 基础篇-Windows保护模式
  4. 源码编译安装screen
  5. 通知(Toast+Notification)
  6. EL表达式 入门
  7. Nginx反向代理+DNS轮询+IIS7.5 千万PV 百万IP 双线 网站架构案例
  8. ContentProvider初阶Cookbook
  9. tomcat加入系统服务
  10. FPGA学习笔记(二)——FPGA学习路线及开发流程
  11. C#细说多线程
  12. Java 语言特性
  13. vue 和react的区别
  14. android toolbar使用记录
  15. 4.html基础标签:表单
  16. java中Integer和int的区别(转)
  17. NESTED内部事务异常会回滚 外部事务不会回滚 ;内部事务没有异常,外部事务有异常 则整体事务都回滚
  18. STM32F4 External interrupts
  19. [Winform]安装在C盘,无操作权限的一个解决办法
  20. MySQL事物系列:3:innodb_flush_log_at_trx_commit小实验

热门文章

  1. Markdown简要规则
  2. strophe与openfire模拟的XMPP简单hello程序
  3. Ros学习——值得学习的package
  4. mongodb 降序
  5. 分布式锁2 Java非常用技术方案探讨之ZooKeeper 【转载】
  6. HDOJ 1097 A hard puzzle
  7. Halcon从某一个图片以指定区域绘制到另一个图像
  8. SSH框架(四) struts2+spring3.0的登陆示例
  9. deb包制作(转)
  10. Python中的切片操作