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;

}                                 


 

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