Lightoj1227——Boiled Eggs(贪心)
来源:互联网 发布:棋牌源码交易 编辑:程序博客网 时间:2024/05/16 09:45
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, ithad 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<stdio.h>#include<algorithm>#include<string.h>#include<iostream>#include<cmath>#define MAXN 10000using namespace std;int main(){ int p,q,a[100],sum; int t,cnt=1,i,j,m,n; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&p,&q); for(i=0; i<n; ++i) cin>>a[i]; sum=j=0; for(i=0; i<n; ++i) { if(sum+a[i]<=q&&i+1<=p) { sum+=a[i]; j++; } else break; } printf("Case %d: %d\n",cnt++,j); } return 0;}
- Lightoj1227——Boiled Eggs(贪心)
- UVa 11900 - Boiled Eggs
- lightOJ 1227 - Boiled Eggs
- light oj 1227 - Boiled Eggs
- eggs(递归)
- eggs(递归)
- eggs
- ZSTUOJ 4214: Power Eggs(经典动态规划——鹰蛋问题)
- HDU 3820 Golden Eggs (最小割)
- hdu3820 Golden Eggs(最小割)
- 【CodeForces 282B】Painting Eggs(模拟)
- 2-eggs-100-floors-puzzle(扔两个鸡蛋问题)
- 2015浙江理工校赛 E Power Eggs (DP)
- HDU 3820 Golden Eggs(最大独立集)
- hdu 3820 Golden Eggs(最小割+SAP)
- Python Eggs
- Painting Eggs
- two eggs
- RSA加密历史由来
- div+css之清除浮动
- 【杭电oj】1225 - Football Score(结构体排序)
- Android之WebViewClient与WebChromeClient的区别
- [JavaScript/JQuery] js数组删除,新增,元素删除,事件绑定
- Lightoj1227——Boiled Eggs(贪心)
- rplidar A2 在机器人上的安装说明
- nodejs爬虫编码问题
- ubuntu 安装vmware
- [JavaScript/JQuery] js数组去重的4个方法
- NOIP2013普及组 T2 表达式求值
- zzulioj1861(最长回文子串)
- Apache 日志切割工具cronolog详解
- ZOJ 2975 Kinds of Fuwas【思维】