zoukankan      html  css  js  c++  java
  • Codeforces Round #316 (Div. 2) A 水

    A. Elections
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

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

    题意:投票选州长  m个城市 n个候选人    给你n个候选人在每个城市的得票数   在当前城市获票最多的候选人获胜 当票数一样时 编号小的

    候选人获胜  统计获得城市获胜最多的候选人作为州长  当出现获胜次数相同的情况下 输出编号最小的一名

            

    题解: 水

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<queue>
     5 #include<stack>
     6 #include<vector>
     7 #include<map>
     8 #include<algorithm>
     9 #define ll __int64
    10 #define mod 1e9+7
    11 #define PI acos(-1.0)
    12 using namespace std;
    13 int n,m;
    14 int exm;
    15 int biao;
    16 map<int,int> mp;
    17 int main()
    18 {
    19     int ans=0;
    20     int maaa=0;
    21     scanf("%d %d",&n,&m);
    22     mp.clear();
    23     for(int i=1;i<=m;i++)
    24     {
    25         int biao=0;
    26         int maxn=-1;
    27         for(int j=1;j<=n;j++)
    28         {
    29             scanf("%d",&exm);
    30             if(exm>maxn)
    31             {
    32                 maxn=exm;
    33                 biao=j;
    34             }
    35         }
    36         mp[biao]++;
    37         if(mp[biao]>maaa||(mp[biao]==maaa&&biao<ans))
    38         {
    39             maaa=mp[biao];
    40             ans=biao;
    41         }
    42     }
    43     cout<<ans<<endl;
    44     return 0;
    45 }
  • 相关阅读:
    Sqlserver 实际开发中表变量的用法
    Python Day 20 面向对象 (面向对象的组合用法,面向对象的三大特性
    Python Day 19 面向对象(初识面向对象)
    Python Day 18 常用模块(模块和包)
    Python Day 17 常用模块(常用模块一 时间模块,random模块,os模块,sys模块,序列化模块)
    Python Day 15 函数(递归函数、二分查找算法)
    Python Day 14 函数(内置函数,匿名函数(lambda表达式))
    Python Day 13 函数(迭代器,生成器,列表推导式,生成器表达式)
    Python Day 11 + Python Day 12 函数(函数名的应用,闭包,装饰器)
    Python Day 10 函数(名称空间,作用域,作用域链,加载顺序等; 函数的嵌套 global,nonlocal)
  • 原文地址:https://www.cnblogs.com/hsd-/p/5685190.html
Copyright © 2011-2022 走看看