杭电-1304A Contesting Decision(结构体)

本文介绍了一个编程竞赛评分系统的实现细节,包括如何计算参赛队伍解决的问题数量及罚时,并通过示例输入输出展示评分过程。

A Contesting Decision

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 696    Accepted Submission(s): 504


Problem Description
Judging a programming contest is hard work, with demanding contestants, tedious decisions, and monotonous work. Not to mention the nutritional problems of spending 12 hours with only donuts, pizza, and soda for food. Still, it can be a lot of fun.
Software that automates the judging process is a great help, but the notorious unreliability of some contest software makes people wish that something better were available. You are part of a group trying to develop better, open source, contest management software, based on the principle of modular design.

Your component is to be used for calculating the scores of programming contest teams and determining a winner. You will be given the results from several teams and must determine the winner.

Scoring

There are two components to a team's score. The first is the number of problems solved. The second is penalty points, which reflects the amount of time and incorrect submissions made before the problem is solved. For each problem solved correctly, penalty points are charged equal to the time at which the problem was solved plus 20 minutes for each incorrect submission. No penalty points are added for problems that are never solved.

So if a team solved problem one on their second submission at twenty minutes, they are charged 40 penalty points. If they submit problem 2 three times, but do not solve it, they are charged no penalty points. If they submit problem 3 once and solve it at 120 minutes, they are charged 120 penalty points. Their total score is two problems solved with 160 penalty points.

The winner is the team that solves the most problems. If teams tie for solving the most problems, then the winner is the team with the fewest penalty points.
 

Input
For the programming contest your program is judging, there are four problems. You are guaranteed that the input will not result in a tie between teams after counting penalty points.

Line 1 <nTeams>
Line 2-n+1 <Name> <p1Sub> <p1Time> <p2Sub> <p2Time> ... <p4Time>

The first element on the line is the team name, which contains no whitespace. Following that, for each of the four problems, is the number of times the team submitted a run for that problem and the time at which it was solved correctly (both integers). If a team did not solve a problem, the time will be zero. The number of submissions will be at least one if the problem was solved.
 

Output
The output consists of a single line listing the name of the team that won, the number of problems they solved, and their penalty points.
 

Sample Input
4 Stars 2 20 5 0 4 190 3 220 Rockets 5 180 1 0 2 0 3 100 Penguins 1 15 3 120 1 300 4 0 Marsupials 9 0 3 100 2 220 3 80
 

Sample Output
Penguins 3 475
 

就是一个oj的排名计算过程


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node {
    char name[100];
    int a[4],b[4];
    int sum;
    int score;
}lis[10000];
bool cmp(node x,node y)
{
    if(x.sum!=y.sum)
        return x.sum>y.sum;
    else
        return x.score<y.score;
}
int main()
{
    int n,a,b,i,j;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0;i<n;i++)
        {
            int t=0,r=0;
            scanf("%s",lis[i].name);
            for(j=0;j<4;j++)
            {
                scanf("%d%d",&lis[i].a[j],&lis[i].b[j]);
                if(lis[i].b[j])
                    t++;
                if(lis[i].a[j]>1&&lis[i].b[j])
                    r=r+(lis[i].a[j]-1)*20+lis[i].b[j];
                if(lis[i].a[j]==1)
                    r+=lis[i].b[j];
            }
            lis[i].sum=t;
            lis[i].score=r;
        }
        sort(lis,lis+n,cmp);
        printf("%s %d %d\n",lis[0].name,lis[0].sum,lis[0].score);
    }
    return 0;
}




Task 3: Simulate Election (4 marks) To select the winner of the election, instant-runoff voting (IRV) is used. This method selects a winner over the course of a number of rounds. The following procedure is repeated until there is only one candidate left: Assign each ballot to the candidate who is ranked highest on that ballot and who has not yet been eliminated. Eliminate the candidate(s) with the lowest number of assigned ballots in that round, so they are not counted in future rounds. For this task, you must run a simulated IRV for an election given a list of valid positional ballots. Write a function simulate_election(ballots, parties) You need to write a function that returns the full history of elimination rounds for the given election. Arguments: ballots: a list of valid positional ballots. parties: the ordered list of parties contesting the election. Returns: a list of elimination round history, where each round consists of a tuple with: A dictionary mapping each remaining candidate to their vote total A set of candidates to be eliminated after that round. Details: If two candidates are tied for the lowest vote total in a round, they are both eliminated simultaneously If there is no unique winner, your program should raise a TiedElectionError as defined at the top of the provided code. As a reminder, you can raise an error using the built in Python statement raise TiedElectionError. This is a custom Exception type that we have defined for you. You can use it like any other Exception , and there is no need to understand how we have defined it. Interested students can learn more about custom object and classes in this optional worksheet. Example Calls:
最新发布
10-17
Task 4: Print Election Results (4 marks) In order to allow transparent auditing, each simulated election must produce a printed paper trail. Write a function print_results(election_results, parties) You need to write a function that prints a summary certificate of each election round in a precise tabular format. Arguments: election_results: a list of round histories from the simulated election, as described in the previous task. parties: the ordered list of parties contesting the election. Returns: None Details: You may assume that all parties in election_results are valid parties in parties , and that there are no more than ten rounds in election_results. The formatting requirements for the certificate are extremely strict, ensure you follow the rules below precisely. The certificate must not exceed 80 characters in width (including borders and padding). The certificate starts and ends with a padding row. These consist of one border line and two blank lines. The entire certificate is bordered on all four sides with the character '= '. Between the padding rows is the election data in a tabular format. The tabular format consists of a single header column (containing the round numbers), and n data columns where n is the number of parties in parties The header column should be left aligned and seven characters wide. All data should be the same width (c): c should be equal to the width of the longest unabbreviated party name, if this does not cause the certificate to exceed the width limit (80 chars). If it does cause the certificate to exceed the width limit, c should instead be the largest integer such that the certificate remains within the limit. Between each column (and between the first and last column and the border), there should be a single space. This is not counted in the column widths above. The history is then printed in a series of rows, one header row and m data rows where m is the number of rounds in election_results. The header row consists of a single line with: "Round:" in the header column (left aligned) The party names in the data columns (left aligned) Each party name which is longer than c should be abbreviated by taking the first character of each word, where word is defined by any sequence of characters separated by spaces. You may assume this abbreviation is unique, and fits in the required width. Other party names should be unchanged. Each data row consists of two lines: In the header column (left aligned): the first line should have number of the round (e.g. "Second"), and the second line should be blank. In the data columns (all right aligned): the first line should have the number of votes assigned to that party in that round as an integer. You may assume this always fits within the column width. the second line should display the first c characters of "eliminated" if that party was eliminated in that round, otherwise it should be blank. Between each non-padding row should be a single blank line.
10-17
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值