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;
    }
     
  • 相关阅读:
    魅力惠_百度百科
    新奢侈主义_百度百科
    FastSocket学习笔记~再说客户端与服务端的组成
    在线支付文章索引(支付宝_微信_银联)
    微信JSApi支付~微信支付代理模式的实现(原创)
    爱上MVC~ajax调用分部视图session超时页面跳转问题
    C#~异步编程再续~await与async引起的w3wp.exe崩溃-问题友好的解决
    poj-3895-Cycles of Lanes 简单DFS
    How to search a table in a store proc and open the store proc
    Github-Client(ANDROID)开源之旅(四) ------ 简介Roboguice
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702820.html
Copyright © 2011-2022 走看看