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. Elasticsearch之curl创建索引

    前提,是 Elasticsearch之curl创建索引库 [hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT 'http://192.168.80.200: ...

  2. python之数据库的操作(课前准备)

    数据库(Database)是按照数据结构来组织.存储和管理数据的仓库. 上面的就是数据库的定义. 何为数据库,简单的来说,就是我们的大型数据的存放地点. 而我们学习的呢就是数据库的访问层的制作. 何为 ...

  3. sql 一些偶尔会用到的写法和函数 不定时更新

    小数转整数: --round() 遵循四舍五入把原值转化为指定小数位数,如: ) -- =1 ) -- =2 --floor() 向下舍入为指定小数位数 如: SELECT floor(1.45) - ...

  4. poj1753-Flip Game 【状态压缩+bfs】

    http://poj.org/problem?id=1753 Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  5. win10获取超级管理员权限脚本实现

    建立一个TXT文件,把下面的脚本贴到里面,然后把后缀改成reg格式,双击添加到注册表就可以了, win10_1703版本亲测可用.... Windows Registry Editor Version ...

  6. 服务机器人的小脑——SLAM技术

    博客转载自:https://www.leiphone.com/news/201706/DZlMscTwdIzFyodg.html 雷锋网(公众号:雷锋网)按:本文作者SLAMTEC(思岚科技公号sla ...

  7. 3.3PCL已有点类型介绍和增加自定义的点类型

    1.PCL中有哪些可用的PointT类型 这些point类型都位于point_types.hpp文件中,如果用户需要自己定义类型,需要对已有类型了解. 1)PointXYZ---成员变量:float ...

  8. Python程序设计8——网络编程

    Python是一个很强大的网络编程工具,python内有很多针对场景网络协议的库,在库顶部可以获得抽象层,这样就可以集中精力在程序的逻辑处理上,而不是停留在网络实现的细节中. 1 少数几个网络设计模块 ...

  9. jquery 使用记录

    1.jquery 筛选一个属性符合多个条件  var myTag=$("input[id=myid][name=myname][type=button]").length; 2.j ...

  10. grep多条件和sed合并两行

    grep多条件,最简单的方式是使用正则表达式: egrep "条件1|条件2"   sed合并两行,将 1 2 3 4 合并成: 1 2 3 4 sed '$!N;s/\n/\t/ ...