欢迎访问我的个人网站==》 jiashubing.cn

UESTC 1426 Boring Ranking

Boring Ranking
Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu

Description

New term is coming, so the annual scholarship is going to be distributed. But Alibaba can’t wait to know how much he can get. Now he gets all the info including every course’s score and quality score of every student. He is too impatient to ask you for help.

As a UESTCer, you must know the evaluation method of scholarship. If you aren’t familiar with it, you can refer to the following description.

Your score consists of two parts: basis score and quality score.

Basis score is the weighted average score of all courses’ scores. Every course has a weight coefficient. Assume Si and Wi are the score and weight coefficient of the ith course, then the weighted average score is equal to:
                                         
Quality score is up to your performance in science and technology activities, competitions and student works.

At first, all students are ranked by basis score, and divided into 4 groups: top 10%, next 20%, then next 30% and others. And then every student is ranked only in his/her group according to the sum of basic score and quality score.

Alibaba wants to know the final ranklist of top 3 groups because the last 40% can’t get the scholarship. Can you tell him?

Input

The first line of input contains an integer T (T <= 20), which is the number of test cases that follow.

For each test case:

There are two integers N and M (10<=N<=100, 1<=M<=20) in the first line, which is the number of students and courses. 

Then N lines follow, each of them containing a string. The string in ith line is the name of the ith student. All strings only consist of lowercase letters and the length isn’t larger than 20.

Then a single line follows containing M integers. The ith integer is Wi indicating the weight coefficient of the ith course. All weight coefficients are in the range [1,6].

Then N lines follow, each of them containing M integers separated by single spaces. The jth element in the ith line is the jth course’s score of the ith student. All scores are in the range [0,100].

Then N lines follow, each of them containing a single integer indicating the quality score. All scores are in the range [0,20].

You can assume every student’s name, basis score and final score are unique, and N is a multiple of 10.

Output

For every test case, you should output "Case #k:" first in a single line, where k indicates the case number and starts at 1. Then output the final ranklist of top 3 groups who get the scholarship. Print a blank line between every two adjacent groups, and print a blank line after every test case.

Sample Input

1
10 1
standy
totalfrank
total
frank
frost
joyzhang
uestc
uestcmelody
acm
icpc
5
90
92
65
30
50
60
85
95
80
88
10
3
12
8
6
3
5
1
20
5

Sample Output

Case #1:
uestcmelody

standy
totalfrank

acm
icpc
uestc

题目大意:给定10的倍数个学生的成绩(基础成绩和品质成绩),然后排序出能获得奖学金的学生,其中先按基础成绩排名,分成四组,分别占10%,20%,30%,40%,然后对前三组,按总成绩(基础成绩+品质成绩)排名。

题目的意思不难理解,而且也是很好写的模拟题目,但是有很多小点需要注意,最需要注意的是doule转int精度损失问题

以下是转发大牛博客上的解释:

double f;

int num =(int) f*100;

结果是:输入f = 1.23,  输出 num = 122.

  输入f = 1.25  输出 num =125

这就是著名的double精度损失问题。

因为1.23在计算机里面只能表示为近似值:1.2299999999.........

而1.25却能被精确的表示:

解决的办法是:

int num = (int)(f*100+0.0001),这个0.0001根据你需要的精度来设置,是可以改变的

这时候,不管f=1.23还是f=1.25,结果都是我们想要的123和125.

关键是要理解:  10110101 只是近似等于 1.0110101 * 2^7.

 

其他的问题还有用sort排序,而不用qsort排序;用个gets(s),而不用getchar();

代码如下:

View Code
 1 # include<stdio.h>
 2 # include<string.h>
 3 # include<stdlib.h>
 4 # include<iostream>
 5 # include<algorithm>
 6 using namespace std;
 7 //# define eps 1e-9 高手经常把这个eps定义上,来防止精度损失
 8 struct node{
 9     char name[22];
10     double basis;
11     double    quality;
12 }st[110];
13 double w[25],sum;
14 int n,m;
15 
16 //使用qsort排序就会出错,不知道为什么
17 int cmp1(node a,node b){
18     return a.basis > b.basis;
19 }
20 int cmp2(node a,node b){
21     return a.quality > b.quality;
22 }
23 
24 int main(){
25     int T,cas,i,j;
26     double t;
27     char ss[22];
28     scanf("%d",&T);
29     for(cas=1;cas<=T;cas++)
30     {
31         scanf("%d%d",&n,&m);
32         gets(ss);    //getchar()也会出错
33         for(i=0;i<n;i++)
34             gets(st[i].name);        
35         sum = 0;    
36         for(i=0;i<m;i++)
37         {
38             scanf("%lf",&w[i]);
39             sum += w[i];
40         }
41         for(i=0;i<n;i++)
42         {
43             double temp=0;    
44             for(j=0;j<m;j++)
45             {
46                 scanf("%lf",&t);
47                 temp += t*w[j];
48             }
49             st[i].basis = (double)temp/sum;
50         }        
51         for(i=0;i<n;i++)
52         {
53             scanf("%lf",&st[i].quality);
54             st[i].quality += st[i].basis;
55         }        
56         
57         int t1,t2,t3;
58 
59         //double精度损失
60         t1=int(n*0.1+0.1);
61         t2=int(n*0.2+0.1);
62         t3=int(n*0.3+0.1);
63 
64         //sort排序也是可以一段一段的排的
65         sort(st,st+n,cmp1);
66         sort(st,st+t1,cmp2);
67         sort(st+t1,st+t1+t2,cmp2);
68         sort(st+t1+t2,st+t1+t2+t3,cmp2);
69 
70         printf("Case #%d:\n",cas);
71         for(i=0;i<t1;i++)
72             printf("%s\n",st[i].name);
73         puts("");
74         for(;i<t1+t2;i++)
75             printf("%s\n",st[i].name);
76         puts("");
77         for(;i<t1+t2+t3;i++)
78             printf("%s\n",st[i].name);
79         puts("");
80     }
81     return 0;
82 }

 

 

posted @ 2013-05-09 21:01  贾树丙  阅读(204)  评论(0编辑  收藏  举报