zoukankan      html  css  js  c++  java
  • 7-28 Review of Programming Contest Rules (30分)

    The ACM ICPC's rule of scoring is as the following:

    A problem is solved when it is accepted by the judges. Teams are ranked according to the most problems solved. For the purposes of awards, or in determining qualifier(s) for the World Finals, teams who solve the same number of problems are ranked by least total time. The total time is the sum of the time consumed for each problem solved. The time consumed for a solved problem is the time elapsed from the beginning of the contest to the submittal of the accepted run plus 20 penalty minutes for every rejected run for that problem regardless of submittal time. There is no time consumed for a problem that is not solved.

    For example, if one has the following contest record:

    • At the 100th minute submitted problem A, rejected;
    • At the 140th minute submitted problem B, rejected;
    • At the 150th minute submitted problem B, accepted;
    • At the 160th minute submitted problem C, accepted.

    Then his total time = (150+20) + 160 = 330. Notice that it took him only 10 minutes to finish problem C. Assume that he spent 40 minutes on reading all the problems through, then if he could do problem C first and problem A last, his contest record might look like:

    • At the 50th minute submitted problem C, accepted;
    • At the 90th minute submitted problem B, rejected;
    • At the 100th minute submitted problem B, accepted;
    • At the 160th minute submitted problem A, rejected.

    Then his total time would be 50 + (100+20) = 170. Hence the order of solving the problems will affect one's final rank.

    Now suppose that you are in a one-person team. It will take you t0​​ minutes to read all the problems through. Judging by your experience, you may estimate the minutes ti​​ that you will take to solve problem i. And more, the earlier you get one problem done, the more unlikely that you will make mistakes on programming. Assume that if a solution is first time submitted in the first hour (60 minutes inclusive), it will get accepted at once; if it is first time submitted in the second hour, it will be rejected once; if it is first time submitted in the third hour, it will be rejected twice; etc. You may also estimate the minutes di​​ for debugging problem i every time it is rejected. For the sake of simplicity, let us assume that di​​ is fixed for each problem i, and once you start working on a problem, you will keep submitting until it is accepted.

    Your task is to write a program to find yourself the order of solving the problems which gives you the best chance of winning the contest.

    Input Specification:

    Each input file contains several test cases. For each test case, the 1st line contains 3 integers: the total number of contest hours H (0 H ≤ 5), the total number of problems N (0 N ≤ 9), and the time t0​​ (minutes) for you to read through all the problems at the beginning of the contest. The following N lines each contains a problem's name and a pair of positive integers ti​​ and di​​. A problem's name is a string of no more than 20 characters without any space. A negative H signals the end of input.

    Output Specification:

    For each test case, you are supposed to print to standard output the total time in a line in the format shown by the sample. Then print the names of the problems you will solve in the correct order, each name in a line. If there are several solutions, you must output the smallest sequence. A sequence of problems { i1​​, i2​​, ... in​​ } is smaller than another sequence { j1​​, j2​​, ... jn​​ } means that there exists an integer K between 1 and n such that for every 1, we have ik​​=jk​​, and iK​​<jK​​.

    Sample Input:

    2 3 40
    A 60 10
    B 40 10
    C 10 20
    2 3 40
    Try_This_One 20 5
    And_This_One 20 5
    Then_This_One 20 5
    -1
    
     

    Sample Output:

    Total Time = 170
    C
    B
    Total Time = 295
    Try_This_One
    And_This_One
    Then_This_One

    dfs找出最好的方案,注意60分钟仍然属于第一个小时,61分钟属于第二小时。
    代码:
    #include <cstdio>
    
    using namespace std;
    
    int h,n,t0,ti[10],di[10],vis[10];
    char name[10][21];
    int temp[10],ans[10],max_num,min_time;
    void dfs(int num,int atime,int time) {///完成题目数  完成题目的总时间(加上罚时)  当前花费总时间
        if(time > h) return;
        if(num > max_num || (num == max_num && atime < min_time)) {
            max_num = num;
            min_time = atime;
            for(int i = 0;i < num;i ++) {
                ans[i] = temp[i];
            }
        }
        if(num >= n) return;
        for(int i = 0;i < n;i ++) {
            if(vis[i]) continue;
            vis[i] = 1;
            temp[num] = i;
            dfs(num + 1,atime + time + ti[i] + (time + ti[i] - 1) / 60 * (di[i] + 20),time + ti[i] + (time + ti[i] - 1) / 60 * di[i]);
            vis[i] = 0;
        }
    }
    int main() {
        while(scanf("%d",&h) && h >= 0) {
            scanf("%d%d",&n,&t0);
            max_num = 0;
            h = h * 60;
            for(int i = 0;i < n;i ++) {
                scanf("%s%d%d",name[i],&ti[i],&di[i]);
            }
            dfs(0,0,t0);
            printf("Total Time = %d
    ",min_time);
            for(int i = 0;i < max_num;i ++) {
                printf("%s
    ",name[ans[i]]);
            }
        }
        return 0;
    }
  • 相关阅读:
    Delphi XE2 之 FireMonkey 入门(16) 滤镜: 实例测试
    Delphi XE2 之 FireMonkey 入门(20) TStyleBook(皮肤、样式相关)
    Delphi XE2 之 FireMonkey 入门(18) TLang(多语言切换的实现)
    Delphi XE2 之 FireMonkey 入门(15) 滤镜: 获取滤镜信息
    ASP.NET中常用功能代码总结(7)——利用Jmail发送和接收邮件
    使用.NET Remoting开发分布式应用——基于租约的生存期
    一个SOA时代的到来,看CSDN新闻有感
    .NET设计模式(3):抽象工厂模式(Abstract Factory)
    ASP.NET中常用功能代码总结(3)——上传图片到数据库
    人的一生 有三件事情不能等
  • 原文地址:https://www.cnblogs.com/8023spz/p/12272300.html
Copyright © 2011-2022 走看看