zoukankan      html  css  js  c++  java
  • POJ

    POJ - 1245 Programmer, Rank Thyself

    Time Limit: 1000MS

     

    Memory Limit: 10000KB

     

    64bit IO Format: %I64d & %I64u

    [Submit]   [Go Back]   [Status]  

    Description

    Implement a ranking program similar to the one used for this programming contest.

    Input

    The input file contains one or more contests followed by a line containing only zero that signals the end of the file. Each contest begins with a line containing a positive integer c no greater than 20 indicating the number of teams in the contest, and is followed by c lines that contain a team name and the solution times for seven problems, separated by spaces. Team names consist of between one and ten letters. All team names within a contest are unique. Times are nonnegative integers no greater than 500. 

    As described in the Notes to Teams, teams are ranked first by greatest number of problems solved, then by least total time, then by least geometric mean of all nonzero times. Teams that are still tied are given the same numeric ranking and are listed in alphabetical order, using case-sensitive string comparison. The numeric ranking for a team is always one more than the number of teams ranked ahead of (not tied with) that team. For this problem all geometric means will be rounded to an integer as described below, and only the rounded value will be used when computing rankings and displaying results. 

    If all times are zero, then the geometric mean is also zero. Otherwise, if there are n nonzero times t1, ..., tn, then the geometric mean is defined to be 

    exp ((ln t1 + ln t2 + ... + ln tn) / n) 

    where exp x means ex and ln x means the natural logarithm of x. (There are other mathematically equivalent definitions of the geometric mean, but they may produce slightly different answers due to roundoff and/or overflow problems. Use this definition to get the same answers as the judges.) After computing the geometric mean, round it to an integer by adding 0.5 and truncating any fractional digits. (C/C++ and Java automatically truncate fractions when casting a floating-point type to an integral type. In Pascal use the trunc function.) 

    Output

    For each contest you must output the rankings in a table. All tables will have the same width, with the length equal to the number of teams entered in the contest. Use the exact format shown in the examples. Each contest has a numbered header followed by a table with one team entry per line. Each entry contains the ranking, team name, problems solved, total time, geometric mean, and then the individual solution times in the same order they appeared in the input. In the first example all values completely fill their fields. In general you may need to pad values with spaces (never tabs) so that they have the correct field width. The team name is left-justified, and all other fields are right-justified. The ranking always has two digits, including a leading zero if necessary. Spaces will never appear at the beginning or end of lines. 

    Sample Input

    1

    Plutonians 123 234 345 456 167 278 389

    4

    Xap 0 0 0 0 0 0 0

    Foo 20 30 0 50 40 0 10

    Bar 0 50 20 0 10 40 30

    Baz 0 0 0 0 0 0 0

    3

    Venus 213 0 0 57 0 0 0

    Neptune 0 0 0 117 153 0 0

    Mars 0 150 0 0 0 0 120

    0

    Sample Output

    CONTEST 1

    01 Plutonians 7 1992 261 123 234 345 456 167 278 389

    CONTEST 2

    01 Bar        5  150  26   0  50  20   0  10  40  30

    01 Foo        5  150  26  20  30   0  50  40   0  10

    03 Baz        0    0   0   0   0   0   0   0   0   0

    03 Xap        0    0   0   0   0   0   0   0   0   0

    CONTEST 3

    01 Venus      2  270 110 213   0   0  57   0   0   0

    02 Mars       2  270 134   0 150   0   0   0   0 120

    02 Neptune    2  270 134   0   0   0 117 153   0   0

    Source

    Mid-Central USA 2002

    [Submit]   [Go Back]   [Status]  

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<math.h>
     4 #include<stdlib.h>
     5 
     6 struct rank {
     7     char name[12];
     8     int sol, tot, g, p[7], ind;
     9 };
    10 rank ranks[25];
    11 
    12 int comp(const void *c, const void *d)
    13 {
    14     rank *a = (rank *)c;
    15     rank *b = (rank *)d;
    16     if(a->sol > b->sol) return -1;
    17     else if(a->sol < b->sol) return 1;
    18     else {
    19         if(a->tot < b->tot) return -1;
    20         else if(a->tot > b->tot) return 1;
    21         else {
    22             if(a->g < b->g) return -1;
    23             else if(a->g > b->g) return 1;
    24             else {
    25                 return strcmp(a->name, b->name);
    26             }
    27         }
    28     }
    29 
    30 }
    31 
    32 int main()
    33 {
    34 //    freopen("data.in", "r", stdin);
    35 //    freopen("data.out", "w", stdout);
    36     int n = 0, cnt = 1;
    37     while(scanf("%d", &n)) {
    38         if(!n) break;
    39         for(int i = 0; i < n; i++) {
    40             double t = 0;
    41             ranks[i].sol = 0, ranks[i].tot = 0, ranks[i].g = 0;
    42             scanf("%s", &ranks[i].name);
    43             for(int j = 0; j < 7; j++) {
    44                 scanf("%d", &ranks[i].p[j]);
    45                 if(ranks[i].p[j]) {
    46                     ranks[i].sol++;
    47                     ranks[i].tot += ranks[i].p[j];
    48                     t += log((double)ranks[i].p[j]);
    49                 }
    50             }
    51             if(ranks[i].sol > 0) {
    52                 ranks[i].g = exp(t/ranks[i].sol) + 0.5;
    53             }
    54         }
    55         qsort(ranks, n, sizeof(rank), comp);
    56         printf("CONTEST %d
    ", cnt);
    57         cnt++;
    58         for(int i = 0; i < n; i++) {
    59             if(i < 9) {
    60                 printf("0");
    61             }
    62             if(i > 0 && ranks[i].sol == ranks[i-1].sol && ranks[i].tot == ranks[i-1].tot && ranks[i].g == ranks[i-1].g) {
    63                 ranks[i].ind = ranks[i-1].ind;
    64             }
    65             else {
    66                 ranks[i].ind = i + 1;
    67             }
    68             printf("%d %-10s %d %4d %3d %3d %3d %3d %3d %3d %3d %3d
    ", ranks[i].ind, ranks[i].name, ranks[i].sol, ranks[i].tot, ranks[i].g,
    69                    ranks[i].p[0], ranks[i].p[1], ranks[i].p[2], ranks[i].p[3], ranks[i].p[4], ranks[i].p[5], ranks[i].p[6]);
    70 
    71         }
    72 
    73     }
    74     return 0;
    75 }
  • 相关阅读:
    windows下phpunit installing[转]
    一个简单的文件后缀获取——不是通过文件名,而是文件内容
    二进制加法
    收藏一个韩国棒子的未知高度居中方法
    带超时+POST/GET方式的获取远程文件,利用file_get_contents
    较深度地递归转义过滤
    利用单元测试在每个层上对 PHP 代码进行检查[转IBM]
    提取TP的一个格式化为json的针对的原始类型函数
    分享一个正则方式的UTF8/GBK中文切割
    NewBaldwinFlash的登场(稍简单的DNN模块)
  • 原文地址:https://www.cnblogs.com/acmicky/p/3221088.html
Copyright © 2011-2022 走看看