zoukankan      html  css  js  c++  java
  • lightoj-1227

    1227 - Boiled Eggs
    PDF (English) Statistics Forum
    Time Limit: 0.5 second(s) Memory Limit: 32 MB
    Three of the trouble-makers went to Malaysia this year. A rest house was booked for them. Unlike other rest houses, this rest house was like a normal duplex house. So, it had a kitchen. And the trouble-makers were given all the ingredients to cook, but they had to cook themselves.

    None of them had any previous cooking experience, but they became very excited and planned to cook so many delicious foods! Ideas were coming from their minds like rains from clouds. So, they went to the super market and bought a lot of extra ingredients for their great recipes. For example, they bought 20 eggs. The excited trouble-makers returned to the rest house and found that the gas stove was not connected to the gas cylinder. So, they became very sad, because it was not possible for them to connect such complex thing. And so many foods were about to be rotten. But luckily, they found the microwave oven working. So, they tried to boil all the eggs using the microwave oven (may be, first time in history)! And they succeeded to boil the eggs!

    Now they have n eggs and a bowl. They put some eggs in the bowl with some water. And after that they put the bowl into the oven to boil the eggs. It's risky to put more than P eggs in the bowl and the bowl can carry at most Q gm of eggs. It takes 12 minutes to boil a bowl of eggs. Now you are given the weight of the eggs in gm, and the trouble-makers have exactly 12 minutes in their hand. You have to find the maximum number of eggs they can boil without taking any risk.

    Input
    Input starts with an integer T (≤ 100), denoting the number of test cases.

    Each case starts with three integers n (1 ≤ n ≤ 30), P (1 ≤ P ≤ 30) and Q (1 ≤ Q ≤ 30). The next line contains n positive integers (not greater than 10) in non-descending order. These integers denote the weight of the eggs in gm.

    Output
    For each case, print the case number and the desired result.

    Sample Input
    Output for Sample Input
    2
    3 2 10
    1 2 3
    4 5 5
    4 4 5 5
    Case 1: 2
    Case 2: 1

    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    
    int arr[40];
    
    int main(){
        
        int T,n,sum,w,num,i;
        
        scanf("%d",&T);
        for(int t=1;t<=T;t++){
            scanf("%d%d%d",&n,&num,&w);
            
            for(i=1;i<=n;i++) scanf("%d",&arr[i]);
            
            sort(arr+1,arr+n+1);
    
            sum = 0;
            for(i=1;i<=min(n,num);i++){
                if(sum+arr[i]>w) break;
                sum += arr[i];
            }
            printf("Case %d: %d
    ",t,i-1);
        }
        
        return 0;
    }
  • 相关阅读:
    许可和授权的研究及其破解
    Citect:How do I translate Citect error messages?
    异步IO模型和Overlapped结构
    SanDisk SecureAccess™ Software
    Asynchronous socket communication
    一种字节转字符串的语法
    【转载】C# Tutorial
    保存项目文件“XXX.csprj”时出错。类没有注册。
    markdown中的注释
    ubuntu上nginx详细安装部署教程
  • 原文地址:https://www.cnblogs.com/yuanshixingdan/p/5563737.html
Copyright © 2011-2022 走看看