博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
A - Elections
阅读量:5095 次
发布时间:2019-06-13

本文共 2804 字,大约阅读时间需要 9 分钟。

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

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 ≤ n1 ≤ i ≤ m0 ≤ 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 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
这一题,容我再去看一遍题意.. 好了,言归正传: 老规矩,先上题意:就是国家选举,这个国家有着奇葩的选举制度,共有n个候选人和m个城市,每个候选人在每个城市获得的选票列成一行,所以共有n行。所有城市获得的选票相加和最大的候选人获胜,那么,当有两个以上候选人所得选票都是最大值怎么办呢,奇葩就奇葩在这里!当这种情况发生的时候,他们就会选输入顺序最靠前的候选人当选总统。。 好了,下面是AC代码:
1 #include
2 #include
3 #include
4 #include
5 #include
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
b[k])//找出最靠前的最大值 37 {38 k=i;39 }40 }41 printf("%d\n",k);42 }43 44 return 0;45 }

 

转载于:https://www.cnblogs.com/Kiven5197/p/5467440.html

你可能感兴趣的文章
Visual Studio基于CMake配置opencv1.0.0、opencv2.2
查看>>
Vue音乐项目笔记(三)
查看>>
遍历Map对象
查看>>
计算剪贴板里仿制的代码行数
查看>>
MySQL索引背后的数据结构及算法原理
查看>>
#Leetcode# 209. Minimum Size Subarray Sum
查看>>
C#语言-04.OOP基础
查看>>
1)session总结
查看>>
PHP深浅拷贝
查看>>
SDN第四次作业
查看>>
ActiveMQ(4) ActiveMQ JDBC 持久化 Mysql 数据库
查看>>
DM8168 DVRRDK软件框架研究
查看>>
django迁移数据库错误
查看>>
epoll学习01
查看>>
yii 跳转页面
查看>>
闭包问题
查看>>
C#一个FTP操作封装类FTPHelper
查看>>
Linux运维基础入门(二):网络基础知识梳理02
查看>>
你所不知道的 CSS 阴影技巧与细节
查看>>
MyBatis框架的使用及源码分析(三) 配置篇 Configuration
查看>>