码迷,mamicode.com
首页 > 其他好文 > 详细

ZOJ-3770(Ranking System)

时间:2015-03-11 17:14:04      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:acm   模拟题   

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):

  1. The ID of the i-th member Ai (0 <=Ai <= 1000000000). The ID of each member is unique.
  2. 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].
  3. 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

 

一开始比赛的时候我没去做这道题,因为好像看起来很复杂的样子,而且竟然还有表格这种东西。

后来发现挺简单的,嗨,那就去A了,可是竟然一个小问题卡了我n久,而且是因为把小数点写成了‘,‘  导致一直WA,醉了,还是不够仔细啊。

题目的大致意思是:

叫你按照等级排序:

首先按照分数来排,若分数相同则按照时间来排,再其次则按照ID来排;

然后叫你输出每个人的LV是多少。

那么就相当于是一个三级排序的变式。毕竟只有6中level,所以把每一个等级的人数算出来然后依次排序就好了。

 

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
	int x;	//保存了序号;
	int id;
	int yy,mm,dd;
	int s;
}a[2005];
bool cmp(node a,node b){
	if(a.s!=b.s)  return a.s>b.s;
	if(a.s==b.s){
		if(a.yy==b.yy && a.mm==b.mm)  return a.dd<b.dd;
		if(a.yy==b.yy)  return a.mm<b.mm;
		return a.yy<b.yy;
	}
	return a.id<b.id;
}
int main(){
	int T,n,sum,k,i,j;
	int f[2005];
	scanf("%d",&T);
	while(T--){
		memset(a,0,sizeof(a));   memset(f,0,sizeof(f));
		scanf("%d",&n);
		sum=0;
		for(i=1;i<=n;i++){
			scanf("%d %d/%d/%d %d",&a[i].id,&a[i].yy,&a[i].mm,&a[i].dd,&a[i].s);
			a[i].x=i;
			//sum是记录大于0的人数; 
			if(a[i].s>0)  sum++;
		}
		int d6,d5,d4,d3;
		sort(a+1,a+1+n,cmp);
		d6=sum*0.03; d5=sum*0.07;  d4=sum*0.2;  d3=sum*0.3;
		for(i=1;i<=n;i++){
			if(!a[i].s)  f[a[i].x]=1;  
			else if(d6)  {f[a[i].x]=6;  d6--; }
			else if(d5)  {f[a[i].x]=5;  d5--; }
			else if(d4)  {f[a[i].x]=4;  d4--; }
			else if(d3)  {f[a[i].x]=3;  d3--; }
			else   {f[a[i].x]=2;  }
		}
		for(i=1;i<=n;i++){
			printf("LV%d\n",f[i]);
		}
	}
}


 另外,在我的验证下,那个id用字符串类型保存也是可以的,

并且在比较的时候直接写  a.id<b.id; 也是可以来判断的;

 

ZOJ-3770(Ranking System)

标签:acm   模拟题   

原文地址:http://blog.csdn.net/acmer_hades/article/details/44201091

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!