Sicily 4873. D’HONDT

2012年每周一赛第二场第一题,简单模拟问题。题目的意思是,对于票数大于5%的政党,将其总票数分别从1除到14,得出14个值,然后把每个政党的这些值混在一起排序,那么最大的14个值所属的政党中,将有一人被选举为代表,然后就是按字典序输出每个政党的代表人数。需要注意的是,即使这个政党没人当选为代表,也是要输出的,只要他的得票数大于总票数的5%。

Run Time: 0sec

Run Memory: 304KB

Code Length: 898Bytes

Submit Time: 2012-03-03 21:45:54

// Problem#: 4873
// Submission#: 1231763
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <cstdio>
#include <map>
using namespace std;

int main()
{
    int X, N, G;
    char P;
    map<char,int> vote, rept;
    map<char,int>::iterator cit;
    map<double,char> score;
    map<double,char>::iterator dit;
    int i;

    scanf( "%d%d", &X, &N );
    for ( i = 1; i <= N; i++ ) {
        getchar();
        scanf( "%c%d", &P, &G );
        if ( (double)G / X >= 0.05 ) {
            vote[ P ] = G;
            rept[ P ] = 0;
        }
    }

    if ( N != 0 ) {
        for ( cit = vote.begin(); cit != vote.end(); cit++ ) {
            for ( i = 1; i <= 14; i++ )
                score[ (double)cit->second / i ] = cit->first;
        }
        for ( i = 1, dit = --score.end(); i <= 14; i++, dit-- )
            rept[ dit->second ]++;

        for ( cit = rept.begin(); cit != rept.end(); cit++ )
            printf( "%c %d\n", cit->first, cit->second );
    }

    return 0;

}                                 


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章