链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5233
题目:
Few weeks ago, a famous software company has upgraded its instant messaging software. A ranking system was released for user groups. Each member of a group has a level placed near his nickname. The level shows the degree of activity of a member in the group.
Each member has a score based his behaviors in the group. The level is determined by this method:
Level | Percentage | The number of members in this level |
---|---|---|
LV1 | / | All members whose score is zero |
LV2 | / | All members who can not reach level 3 or higher but has a positive score |
LV3 | 30% | ⌊(The number of members with a positive score) * 30%⌋ |
LV4 | 20% | ⌊(The number of members with a positive score) * 20%⌋ |
LV5 | 7% | ⌊(The number of members with a positive score) * 7%⌋ |
LV6 | 3% | ⌊(The number of members with a positive score) * 3%⌋ |
- ⌊x⌋ is the maximum integer which is less than or equal to x.
- The member with the higher score will get the higher level. If two members have the same score, the earlier one who joined the group will get the higher level. If there is still a tie, the user with smaller ID will get the higher level.
Please write a program to calculate the level for each member in a group.
Input
There are multiple test cases. The first line of input is an integer T indicating the number of test cases. For each test case:
The first line contains an integer N (1 <= N <= 2000) indicating the number of members in a group.
The next N lines, each line contains three parts (separated by a space):
- The ID of the i-th member Ai (0 <= Ai <= 1000000000). The ID of each member is unique.
- The date of the i-th member joined the group, in the format of YYYY/MM/DD. The date will be in the range of [1900/01/01, 2014/04/06].
- The score Si (0 <= Si <= 9999) of the i-th member.
Output
For each test case, output N lines. Each line contains a string represents the level of the i-th member.
Sample Input
1 5 123456 2011/03/11 308 123457 2011/03/12 308 333333 2012/03/18 4 555555 2014/02/11 0 278999 2011/03/18 308
Sample Output
LV3 LV2 LV2 LV1 LV2
解题思路:
简单的模拟。建立一个排名系统的结构体,对结构体排序即可。
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 2010;
struct RS
{
int index, id, score;
char s[12];
};
RS rs[MAXN];
int level[MAXN];
bool cmp(const RS &a, const RS &b)
{
if(a.score < b.score) return true;
else if(a.score == b.score)
{
if(strcmp(a.s, b.s) > 0) return true;
else if(0 == strcmp(a.s, b.s))
{
if(a.id > b.id) return true;
}
}
return false;
}
int main()
{
int t;
while(~scanf("%d", &t))
{
while(t--)
{
memset(level, 0, sizeof(level));
int n, positive = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%d%s%d", &rs[i].id, rs[i].s, &rs[i].score);
rs[i].index = i;
if(rs[i].score > 0) positive++;
else level[i] = 1;
}
sort(rs, rs + n, cmp);
int num[7];
num[6] = positive * 0.03;
num[5] = positive * 0.07;
num[4] = positive * 0.20;
num[3] = positive * 0.30;
int tmp = n - 1, m = n - 1;
for(int j = 6; j >= 3; j--)
{
while(m - tmp < num[j])
{
level[rs[tmp].index] = j;
tmp--;
}
m = tmp;
}
for(int i = n - positive; i <= m; i++)
{
level[rs[i].index] = 2;
}
for(int i = 0; i < n; i++)
{
printf("LV%d\n", level[i]);
}
}
}
return 0;
}