SRM 145 1A2A 2013.11.30
DIV 1 250
Problem Statement
You have a certain amount of money to giveout as a bonus to employees. The trouble is, who do you pick to receive whatbonus? You decide to assign a number of points to each employee, whichcorresponds to how much they helped the company in the last year. You are givenan vector <int> points, where each element contains the points earned bythe corresponding employee (i.e. points[0] is the number of points awarded toemployee 0). Using this, you are to calculate the bonuses as follows:
- First, add up all the points, this is thepool of total points awarded. - Each employee gets a percentage of the bonusmoney, equal to the percentage of the point pool that the employee got. -Employees can only receive whole percentage amounts, so if an employee's cut ofthe bonus has a fractional percentage, truncate it. - There may be somepercentage of bonus left over (because of the fractional truncation). If n% ofthe bonus is left over, give the top n employees 1% of the bonus. There will beno more bonus left after this. If two or more employees with the same number ofpoints qualify for this "extra" bonus, but not enough bonus is leftto give them all an extra 1%, give it to the employees that come first inpoints.
The return value should be a vector<int>, one element per employee in the order they were passed in. Eachelement should be the percent of the bonus that the employee gets.
Definition
Class:
Bonuses
Method:
getDivision
Parameters:
vector <int>
Returns:
vector <int>
Method signature:
vector <int> getDivision(vector<int> points)
(be sure your method is public)
Constraints
-
points will have between 1 and 50 elements,inclusive.
-
Each element of points will be between 1and 500, inclusive.
Examples
0)
{1,2,3,4,5}
Returns: { 6, 13, 20, 27, 34 }
The total points in the point pool is1+2+3+4+5 = 15. Employee 1 gets 1/15 of the total pool, or 6.66667%, Employee 2gets 13.33333%, Employee 3 gets 20% (exactly), Employee 4 gets 26.66667%, andEmployee 5 gets 33.33333%. After truncating, the percentages look like:{6,13,20,26,33} Adding up all the fractional percentages, we see there is 2% inextra bonuses, which go to the top two scorers. These are the employees whoreceived 4 and 5 points.
1)
{5,5,5,5,5,5}
Returns: { 17, 17, 17, 17, 16, 16}
The pool of points is 30. Each employee got1/6 of the total pool, which translates to 16.66667%. Truncating for allemployees, we are left with 4% in extra bonuses. Because everyone got the samenumber of points, the extra 1% bonuses are assigned to the four that come firstin the array.
2)
{485, 324, 263, 143, 470, 292, 304, 188,100, 254, 296,
255,360, 231, 311, 275, 93, 463, 115, 366,197, 470}
Returns:
{ 8, 6, 4, 2, 8, 5, 5, 3, 1, 4, 5, 4, 6, 3, 5, 4, 1, 8,
1, 6, 3, 8 }
This problem statement is the exclusive andproprietary property of TopCoder, Inc. Any unauthorized use or reproduction ofthis information without the prior written consent of TopCoder, Inc. isstrictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
#include <iostream>
#include <vector>
#include <fstream>
#include <math.h>
using namespace std;
class Bonuses
{
public: vector<int>getDivision(vector <int> points)
{
intflag[100]={0};
intsum = 0, sum2 =0;
intlen=points.size();
vector<int> ans;
for(vector<int>::iteratori=points.begin();i!=points.end();i++)
{
sum+= *i;
}
ans.clear();
for(vector<int>::iterators=points.begin();s!=points.end();s++)
{
inttans= (int)((double)(*s)/(double)sum*100);
ans.push_back(tans);
sum2+=tans;
}
intjend=100-sum2;
inttemp =0, t=0;
for(intj=1;j<=jend;j++)
{
temp=0, t=0;
for(int i=0;i<len;i++)
{
if((ans[i]>temp)&&(flag[i]==0))
{
temp=ans[i];
t=i;
}
}
ans[t]= ans[t]+1;
flag[t]=1;
cout<<ans[t]<<endl;
}
return ans;
}
};
DIV 2 250
Problem Statement
Sometimes when computer programs have alimited number of colors to use, they use a technique called dithering.Dithering is when you use a pattern made up of different colors such that whenthe colors are viewed together, they appear like another color. For example,you can use a checkerboard pattern of black and white pixels to achieve theillusion of gray.
You are writing a program to determine howmuch of the screen is covered by a certain dithered color. Given a computerscreen where each pixel has a certain color, and a list of all the solid colorsthat make up the dithered color, return the number of pixels on the screen thatare used to make up the dithered color. Each pixel will be represented by acharacter in screen. Each character in screen and in dithered will be anuppercase letter ('A'-'Z') representing a color.
Assume that any pixel which is a colorcontained in dithered is part of the dithered color.
Definition
Class:
ImageDithering
Method:
count
Parameters:
string, vector <string>
Returns:
int
Method signature:
int count(string dithered, vector<string> screen)
(be sure your method is public)
Constraints
-
dithered will contain between 2 and 26upper case letters ('A'-'Z'), inclusive.
-
There will be no repeated characters indithered.
-
screen will have between 1 and 50 elements,inclusive.
-
Each element of screen will contain between1 and 50 upper case letters ('A'-'Z'), inclusive.
-
All elements of screen will contain thesame number of characters.
Examples
0)
"BW"
{"AAAAAAAA",
"ABWBWBWA",
"AWBWBWBA",
"ABWBWBWA",
"AWBWBWBA",
"AAAAAAAA"}
Returns: 24
Here, our dithered color could consist ofblack (B) and white (W) pixels, composing a shade of gray. In the picture,there is a dithered gray square surrounded by another color (A).
1)
"BW"
{"BBBBBBBB",
"BBWBWBWB",
"BWBWBWBB",
"BBWBWBWB",
"BWBWBWBB",
"BBBBBBBB"}
Returns: 48
Here is the same picture, but with theouter color replaced with black pixels. Although in reality, the outer pixelsdo not form a dithered color, your algorithm should still assume they are partof the dithered pattern.
2)
"ACEGIKMOQSUWY"
{"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX",
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX",
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX",
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX",
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX",
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX"}
Returns: 150
A picture of vertical stripes, every otherstripe is considered part of the dithered color.
3)
"CA"
{"BBBBBBB",
"BBBBBBB",
"BBBBBBB"}
Returns: 0
The dithered color is not present.
4)
"DCBA"
{"ACBD"}
Returns: 4
The order of the colors doesn't matter.
This problem statement is the exclusive andproprietary property of TopCoder, Inc. Any unauthorized use or reproduction ofthis information without the prior written consent of TopCoder, Inc. isstrictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class ImageDithering
{
public: int count(string dithered, vector<string> screen)
{
intflag[300]={0};
intans=0;
for(string::iteratori=dithered.begin();i!=dithered.end();i++)
{
flag[(*i)]=1;
}
for(vector<string>::iteratorj=screen.begin();j!=screen.end();j++)
{
for(string::iteratork=(*j).begin();k!=(*j).end();k++)
if(flag[(*k)]==1) ans++;
}
returnans;
}
};