HDU 3573 Buy Sticks 解题报告(贪心)
来源:互联网 发布:中网络电视台 编辑:程序博客网 时间:2024/06/07 01:28
Buy Sticks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 727 Accepted Submission(s): 316
Problem Description
Imyourgod need 3 kinds of sticks which have different sizes: 20cm, 28cm and 32cm. However the shop only sell 75-centimeter-long sticks. So he have to cut off the long stick. How many sticks he must buy at least.
Input
The first line of input contains a number t, which means there are t cases of the test data.
There will be several test cases in the problem, each in one line. Each test cases are described by 3 non-negtive-integers separated by one space representing the number of sticks of 20cm, 28cm and 32cm. All numbers are less than 10^6.
There will be several test cases in the problem, each in one line. Each test cases are described by 3 non-negtive-integers separated by one space representing the number of sticks of 20cm, 28cm and 32cm. All numbers are less than 10^6.
Output
The output contains one line for each line in the input case. This line contains the minimal number of 75-centimeter-long sticks he must buy. Format are shown as Sample Output.
Sample Input
23 1 14 2 2
Sample Output
Case 1: 2Case 2: 3
Author
imyourgod (Special Thanks : crackerwang & Louty)
Source
2010 ACM-ICPC Multi-University Training Contest(14)——Host by BJTU
解题报告:题意很容易理解。买20,28,32三种棒,但是商店里只有75cm的,所以买75cm的裁剪,裁剪剩下来的不可以拼接。
给定20,28,32cm棒需要的数量x,y,z,求最少买多少根75cm的棒。
75cm的棒可以裁剪成以下的方式:
3,0,0 -》 a
0,2,0 -》 b
0,0,2 -》 c
2,1,0 -》 d
2,0,1 -》 e
0,1,1 -》 f
假设每种按照裁剪方式的裁剪的棒数量为a,b,c,d,e,f,那么我们可以得出:
3*a + 2*d + 2*e = x (1)
2*b + d + f = y (2)
2*c + e + f = z (3)
而所求的最少的棒即为min(a+b+c+d+e+f)。
(1)(2)(3)三个式子相加,得到 3*a+2*b+2*c+3*d+3*e+2*f = x+y+z。(4)
(4)式两边同加上(b+c+f),得到3*(a+b+c+d+e+f) = x+y+z+b+c+f。(5)
由(5)式我们可以知道,求min(a+b+c+d+e+f)即为求min(b+c+f)+x+y+z。
(2)(3)式相加,得到2*(b+c+f) = y+z-(d+e)。(6)
由(5)(6)得到,6*(a+b+c+d+e+f) = 2*x+3*y+3*z-(d+e)。
由此,即为求(d+e)的最大值。按照此贪心即可。
代码如下:
#include <cstdio>#include <algorithm>int T,cas,a,b,c;int main(){ scanf("%d",&T); while(T--) { scanf("%d%d%d",&a,&b,&c); printf("Case %d: %d\n",++cas,(2*a+3*b+3*c-std::min((a+1)/2,b+c)+5)/6); }}杭电最短代码,哈哈。
0 0
- HDU 3573 Buy Sticks 解题报告(贪心)
- HDU 3573 Buy Sticks 贪心
- HDU 3573 Buy Sticks 贪心--利用率
- HDU 1455Sticks 解题报告
- POJ1065 Wooden Sticks ACM解题报告(暴力贪心)
- hdu 3573 Buy Sticks(数学)
- 贪心之Wooden Sticks ---解题报告
- (贪心)HDU 1789 解题报告
- HDU-1422 重温世界杯 ACM解题报告(贪心)
- POJ1011 Sticks解题报告(经典搜索)
- hdu 4550 卡片游戏 贪心 解题报告
- hdu 4296 Buildings 贪心 解题报告
- HDU 3573 解题报告
- YT04-贪心课堂练习-1005—Wooden Sticks-(6.14日-烟台大学ACM预备队解题报告)
- HDU 1051: Wooden Sticks(贪心)
- hdu 1051 Wooden Sticks (水题,贪心)
- hdu 1051 woolen sticks(贪心)
- HDU -- 1051 Wooden Sticks(贪心)
- 很全的Linux 音频ALSA技术说明
- sql优化记录
- 生活要怎么过
- 黑马程序员--老毕的“模版方法设计模式”
- HDU 2602 Bone Collector (简单的0-1背包)
- HDU 3573 Buy Sticks 解题报告(贪心)
- 第一个十年计划--无情感、实用的高智能全能助理
- List集合去重-- Java
- 工作记录
- 读《春秋》有感之二:尊重对手
- 黄金分割数0.618
- 几种必知的oracle结构图
- OpenGL中FBO的概念及其应用
- mysql内置函数