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
{
int n = p.size();
vector
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
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;
}
salam
ReplyDeletesoale 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?
salam
ReplyDeletekhili dasetun dard nakone ,
vasatun khili doa mikonam hamintori ke moshkelate mano hal mikoni khoda moshkelateto hal kone.