zoukankan      html  css  js  c++  java
  • The Best Strategy

    Carlo Ancelotti "Real Madrid's coach" is so Sad and disappointed, and Florentino Perez fired him after getting knocked out from the UEFA Champions League against Juventus. Carlo is so good in algorithms and strategies (he is an engineer), and he heard about the ACM competition and decided to train a team to qualify to ICPC. After 2 years of training Carlo became really experienced with his team, and now he knows how much time his team needs to solve a problem (read it and code it correctly). Given the required solving time for each problem, help Carlo to determine the highest number of problems his team can solve with the minimum possible penalty.

    Input

    Your program will be tested on one or more test cases. The first line of the input contains a single integer T (1  ≤  T  ≤  100) the number of test cases. Followed by T test cases. Each test case consists of two lines. The first line contains a single integer N (8  ≤  N  ≤  15), the number of problems .The next line consists of N integers separated by a single space: pi (4  ≤  pi  ≤  300) which refers to the solving time for each problem.

    Output

    For each test case print a single line containing "Case n:" (without the quotes) where n is the test case number (starting from 1) followed by a single space, followed by the number of problems his team can solve and the minimum possible penalty.

    Examples

    input

    Copy

    2
    8
    252 244 6 109 294 31 67 270
    8
    218 48 273 69 281 224 250 193
    

    output

    Copy

    Case 1: 4 360
    Case 2: 2 165
    

    Note

    The total penalty is the sum of penalties for all solved problems. The penalty for a solved problem is the time of the accepted submition. And the period of the contest is 300 minutes.

    题意:先从大到小排序,时间相加,要是超过300,跳出,输出题数,和最大时间。

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    int main()
    {
        int n,i,j,a[100],b[100],t,s,o;
        scanf("%d",&t);
        for(o=0;o<t;o++)
        {
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            j=s=0;
            scanf("%d",&n);
            for(i=0;i<n;i++)
            {
                scanf("%d",&a[i]);
            }
            sort(a,a+n);
            b[j++]=a[0];
            for(i=1;i<n;i++)
            {
                b[i]=a[i]+b[i-1];
                if(b[i]>300)
                    break;
            }
            for(j=0;j<i;j++)
            {
                s+=b[j];
            }
            printf("Case %d: %d %d
    ",o+1,i,s);
        }
        return 0;
    }
     
  • 相关阅读:
    selenium3+python自动化9-JS增加、删除、修改HTML元素属性
    selenium3+python自动化8-JS处理滚动条 (2020-02-14 17:35)
    在sql server使用链接服务器中访问mysql
    C# 软件绑定QQ群类开源放出
    时间段控制代码
    C# Aspose.Words.Document.PageCount 踩坑笔记(获取文档页数)
    Sql Server日期转汉字字符串
    C#调用WPS转换文档到PDF的的实现代码。
    SocketException 不知道这样的主机(Quartz.;Dns.GetHostEntry;new HttpChannel)问题记录
    SqlServer 联合Update
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702820.html
Copyright © 2011-2022 走看看