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;
    }
     
  • 相关阅读:
    使用 Eclipse 平台共享代码
    给定一个整数数组,其中元素的取值范围为0到10000,求其中出现次数最多的数
    学习
    eclipse优化
    约瑟夫环
    propedit插件
    OData 11 入门:实现一个简单的OData服务
    OData 14 OData语法(上)
    CLR via C# 读书笔记 54 在使用非托管资源情况下的GC
    面试:等车时间
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702820.html
Copyright © 2011-2022 走看看