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

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

***A. Elections***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.InputThe 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 ≤ 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.OutputPrint a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.

题意:

给出n行m列,代表第i个城市对第j的选手的票数data[i][j],选举分为两次,第一次,每个城市选出这个城市得票最高的选手成为胜利者,如果票数一样,选编号最小的,然后第二轮,选择这些人里面在各个城市被选的胜利次数最多的选手作为最终胜利者,如果次数一样,选编号最小的。

直接上代码:

/*Date : 2015-8-26 晚上Author : ITAKMotto :今日的我要超越昨日的我,明日的我要胜过今日的我;以创作出更好的代码为目标,不断地超越自己。*/#include 
#include
using namespace std;int data[105][105];int ans[105];int main(){ int m, n, j, i, ind; while(cin>>m>>n) { memset(ans, 0, sizeof(ans)); for(i=0; i
>data[i][j]; if(data[i][j] > Max) { Max = data[i][j]; ind = j; } } ans[ind]++; } int Max = -9999; for(i=0; i
Max) { Max = ans[i]; ind = i; } cout<
<

转载地址:http://wsoxa.baihongyu.com/

你可能感兴趣的文章
k3cloud设置同一单据的单据头字段各行合并显示
查看>>
Linux日志管理
查看>>
Gitlab完整搭建手册+排错
查看>>
第28讲 for循环与文件(迭代器解析)
查看>>
php的mcrypt模块
查看>>
简述计算机从加电到启动系统时主板的工作流程
查看>>
js页面缓存问题
查看>>
公交查询系统的设计之详细设计程序流程图(2)
查看>>
Windows版本号的故事
查看>>
QRCode.js:使用 JavaScript 生成二维码
查看>>
深入理解VLAN的形成原理和工作原理
查看>>
【学习笔记】SQL语句处理分组合并
查看>>
SEO独家干货:利用外链投票模型操作新站快速排名
查看>>
【Android游戏开发二十】物理游戏之重力系统开发,让你的游戏变得有质有量!...
查看>>
Windows数据类型探幽——千回百转你是谁?(1)
查看>>
SQL Server 2008概述(一)
查看>>
SQL语言的CASE语句备忘
查看>>
在Windows Server 2008上创建 简单卷
查看>>
微软私有云分享(R2)5-域升级造成Hyper-V主机无法实时迁移
查看>>
详解loadrunner的think time
查看>>