Codeforces 570 A. Elections

click here ~~

                                           ***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.

Input
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?≤?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.

题意:

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

直接上代码:

/*
Date : 2015-8-26 晚上
Author : ITAK

Motto :

今日的我要超越昨日的我,明日的我要胜过今日的我;
以创作出更好的代码为目标,不断地超越自己。
*/
#include <iostream>
#include <cstring>
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<n; i++)
        {
            int Max = -999;
            for(j=0; j<m; j++)
            {
                cin>>data[i][j];
                if(data[i][j] > Max)
                {
                     Max = data[i][j];
                     ind = j;
                }
            }
            ans[ind]++;
        }
        int Max = -9999;
        for(i=0; i<m; i++)
            if(ans[i] > Max)
            {
                Max = ans[i];
                ind = i;
            }
        cout<<ind+1<<endl;
    }
    return 0;
}
/**
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
**/

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-07 00:20:31

Codeforces 570 A. Elections的相关文章

codeforces 570 D. Tree Requests 树状数组+dfs搜索序

链接:http://codeforces.com/problemset/problem/570/D D. Tree Requests time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Roman planted a tree consisting of n vertices. Each vertex contains a low

codeforces 570 D. Tree Requests (dfs)

题目链接: 570 D. Tree Requests 题目描述: 给出一棵树,有n个节点,1号节点为根节点深度为1.每个节点都有一个字母代替,问以结点x为根的子树中高度为h的后代是否能够经过从新排序变成一个回文串? 解题思路: 判断是不是回文串,可以统计集合中出现过的字母的个数,出现奇数次的字母个数小于1,即为回文串,否则不是.所以我们可以使用状压统计当前区间中字母出现的奇偶次数. 对于如何快速的求出区间,先dfs整棵树,标记下来每个节点进栈的时间和出栈的时间,然后把高度一样的点按照进栈时间顺序

codeforces 570 E. Pig and Palindromes (DP)

题目链接: 570 E. Pig and Palindromes 题目描述: 有一个n*m的矩阵,每个小格子里面都有一个字母.Peppa the Pig想要从(1,1)到(n, m).因为Peppa the Pig是一个完美主义者,她想要她所经过的路径上的字母组成的字符串是一个回文串,现在Peppa the Pig想要知道有多少满足条件的走法? 解题思路: 因为经过路径上的字母要组成回文串,所以可以从(1,1),(n,m)同时开始dp.从(1,1)出发只能向下方和右方走,从(n,m)出发只能向上

codeforces 570 E. Pig and Palindromes

题意:给出n*m的字母表,求从左上角走到右下角能形成多少个回文串,只能往下或往右走. 做法:dp[r1][c1][r2][c2],从左上角走到(r1,c1),从右下角走到(r2,c2)时,能形成多少个回文串,因为爆内存,表示成dp[step][r1][r2],从左上角走到r1行,从右下角走到r2行,分别走了step步时,能形成多少个回文串,因为c1=step+2-r1,c2=n+m-step-r2,所以是一样的,这样差不多能过了,因为两边最多走250步,所以需要的空间是250*500*500,当

Codeforces 570 B.Simple Game

click here ~~ ***B. Simple Game*** One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let's assume that Misha chose number m, and Andrew chose number a. Then, by using a random ge

[Codeforces]850E - Random Elections

FWT裸题,写了下模板 #include<cstdio> #define ll long long #define r register int #define MN (1<<20) #define MOD 1000000007 char s[MN+5]; int n,ans,f[MN+5]; ll a[MN+5]; inline int mod(int x){return x<MOD?x:x-MOD;} void fwt(int v) { for(r i=0;i<n;

codeforces 570 D Tree Requests

题意:给出一棵树.每一个结点都有一个字母,有非常多次询问,每次询问.以结点v为根的子树中高度为h的后代是否可以经过调整变成一个回文串. 做法: 推断能否够构成一个回文串的话,仅仅须要知道是否有大于一个的奇数数目的字母就可以.为了非常快的訪问到一个区间.记录前缀和就可以.为了省内存,状压奇偶就可以. 为了非常快的找到以结点v为根的子树中高度为h的后代,须要dfs整棵树.然后记录每一个结点第一次訪问它的时间戳以及离开它的时间戳,就能够二分出来. 为了省内存,能够离线处理询问. #include<ma

codeforces 570 c

C. Replacement time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation

【Codeforces 1019A】Elections

[链接] 我是链接,点我呀:) [题意] 每个人都有自己喜欢的队员 但是如果贿赂他们可以让他们更改自己喜欢的队员 问你最少要花多少钱贿赂队员才能让1号队员严格有最多的人喜欢? [题解] 除了1号之外,其他队员最后喜欢的人数不太好确定. 我们可以这样,用up枚举其他人最后喜欢的人数的上限(即除了1之外所有人都不能超过up) 如果某个人的被喜欢人数超过了,则把所有喜欢这个人当中需要贿赂用的钱数最低的几个贿赂了.让他低于up 然后我们再在这种情况下,让1号队员成为最被喜欢的人(选择之前没被贿赂的且原本