Tuesday, January 4, 2011

TopCoder - SRM 145 DIV 1 - Bonuses - getDivision

problem statement

This is a straight forward simulation problem. As described in the problem statement you find each persons percentage amounts and then you have to distribute the left over percentage among those who have greater points and if they have equal points, give extra 1% to who comes first in input and of course keep track of this person not to give extra 1% to him again.

vector getDivision(vector p)
{
    int n = p.size();
    vector out( n );
       
    int sum = accumulate( p.begin(), p.end(), 0 );       
    for(int i = 0; i < n; i ++)
        out[i] = p[i]*100 / sum;
    int sum2 = accumulate( out.begin(), out.end(), 0 );

    vector mark(n, 0);
    for( ; sum2 < 100; sum2 ++)
    {
        int mx = -1, id = 0;
        for(int j = 0; j < n; j ++)
            if( mx < p[j] && mark[j] == 0 )
                mx = p[j], id = j;


        out[id] ++, mark[id] = 1;
    }    
    return out;
}

2 comments:

  1. salam
    soale 694 - The Collatz Sequence UVA mishe begi bayad chekaresh konam ? man har kar kardam Time Limit mishe . mage rahi be gheir az inke tak takesho mohasebe kone ham darim?

    ReplyDelete
  2. salam
    khili dasetun dard nakone ,
    vasatun khili doa mikonam hamintori ke moshkelate mano hal mikoni khoda moshkelateto hal kone.

    ReplyDelete

USACO - Prime Palindromes

I just skimmed the problem statement and panicked of the high boundary of the input, but something inside told me don't worry everyth...