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;
    }
     
  • 相关阅读:
    面试官:你说说互斥锁、自旋锁、读写锁、悲观锁、乐观锁的应用场景
    JAVA 线上故障排查套路,从 CPU、磁盘、内存、网络到GC 一条龙!
    面经分享:看非科班研究生如何转行斩获 ATM 大厂的 Offer ?
    Jmeter JDBC配置
    Jmeter JDBC连接
    js基础用法1
    java实现io读取数据
    mysql语句
    java修改linux文件
    linux永久或临时修改dns
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702820.html
Copyright © 2011-2022 走看看