Codeforces Round #316 (Div. 2) A
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.
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 ≤ 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.
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
3 3
1 2 3
2 3 1
1 2 1
2
3 4
10 10 3
5 1 6
2 2 2
1 5 7
1
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的更多相关文章
- 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 ...
- Codeforces Codeforces Round #316 (Div. 2) C. Replacement 线段树
C. ReplacementTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem ...
- Codeforces Round #316 (Div. 2) C. Replacement
题意:给定一个字符串,里面有各种小写字母和' . ' ,无论是什么字母,都是一样的,假设遇到' . . ' ,就要合并成一个' .',有m个询问,每次都在字符串某个位置上将原来的字符改成题目给的字符, ...
- 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了. 总结:下次一定要注意了,提交前一定要看 ...
- Codeforces Round #316 (Div. 2) D计算在一棵子树内某高度的节点
题:https://codeforces.com/contest/570/problem/D 题意:给定一个以11为根的n个节点的树,每个点上有一个字母(a~z),每个点的深度定义为该节点到11号节点 ...
- 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 ...
- Codeforces Round #316 (Div. 2)
A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #316 (Div. 2) D、E
Problem D: 题意:给定一棵n个点树,每个点有一个字母,有m个询问,每次询问某个节点x的子树中所有深度为k的点能否组成一个回文串 分析:一堆点能组成回文串当且仅当数量为奇数的字母不多于1个,显 ...
- Codeforces Round #316 (Div. 2C) 570C Replacement
题目:Click here 题意:看一下题目下面的Note就会明白的. 分析:一开始想的麻烦了,用了树状数组(第一次用)优化,可惜没用. 直接判断: #include <bits/stdc++. ...
- Codeforces Round #316 (Div. 2B) 570B Simple Game 贪心
题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int IN ...
随机推荐
- 【272】ArcPy处理数据
参考:ArcPy 函数列表(按字母顺序) 参考:在arcgis上用python脚本(arcpy)做数据批处理 1. 导入 ArcPy,定义 Workspace >>> import ...
- 【转】webService概述
一.序言: 大家或多或少都听过WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成分.但是不得不承认的是We ...
- <!doctype html>这个是干什么的???
html5标准网页声明,原先的是一串很长的字符串,现在是这个简洁形式,支持html5标准的主流浏览器都认识这个声明.表示网页采用html5
- Guava Cache本地缓存
Guava介绍 Guava是一种基于开源的Java库,其中包含谷歌正在由他们很多项目使用的很多核心库. 这个库是为了方便编码,并减少编码错误. 这个库提供用于集合,缓存,支持原语,并发性,常见注解,字 ...
- 指静脉屏幕说明usart hmi
1. 1.usart HMI 下载最新版软件 2.如上图可以设置横屏 3.txt的最大字符默认是10 要改大一些 4.t0.txt="aaa" 这是串口通讯命令但前面还有开始码
- 服务机器人的小脑——SLAM技术
博客转载自:https://www.leiphone.com/news/201706/DZlMscTwdIzFyodg.html 雷锋网(公众号:雷锋网)按:本文作者SLAMTEC(思岚科技公号sla ...
- Luogu 1357 花园
发现$m$很小,直接状压起来,可以处理出一开始的合法的状态. 对于每一个合法的状态,可以处理出它的转移方向,即在后面填一个$1$或者填一个$0$,反着处理比较方便. 考虑一下环的情况,在这题中有一个小 ...
- SDUT 3343 数据结构实验之二叉树四:还原二叉树
数据结构实验之二叉树四:还原二叉树 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 给定一棵 ...
- java反射机制的进一步理解
承上一篇. JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法:这种动态获取的信息以及动态调用对象的方法的功能称为java语 ...
- 百度地图android客户端的AndroidMainfest.xml的学习和android版本号
平时写android产品相关的东西接触比较少,于是找个例子学习下. 众所周知,Apk文件是可以反编译的,虽然看不到代码,xml还是可见的. 把百度地图android客户端反编译之后,来学习下它的And ...