B Buy Sticks
来源:互联网 发布:行业数据 编辑:程序博客网 时间:2024/05/27 00:50
Problem Description
Imyourgod need 3 kinds of sticks which havedifferent sizes: 20cm, 28cm and 32cm. However the shop only sell75-centimeter-long sticks. So he have to cut off the long stick. How manysticks 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 testcases are described by 3 non-negtive-integers separated by one spacerepresenting the number of sticks of 20cm, 28cm and 32cm. All numbers are lessthan 10^6.
Output
The output contains one line for each line inthe input case. This line contains the minimal number of 75-centimeter-longsticks he must buy. Format are shown as Sample Output.
Sample Input
2
3 1 1
4 2 2
Sample Output
Case 1: 2
Case 2: 3
摘自HDOJ 3573!
这道题比较简单,首先当然是先将一根75cm长的棍子分成三段最理想, 有如下3种分法:
A、20+20+28
B、20+20+30
C、20+20+20
我们可以分为三步:
第一步当然是尽量先切出A、B两种,也就是切出一个28(或32)和两个20;
第二步是看20的数目够不够(>=3),能切出三段20来不;
第三步时,三种长度的棍子剩下的情况如何呢?想想……
(还能切出3段不?呃……不能了!那剩下的就切两段吧!)
#include<iostream>using namespace std;int main(){ int i,j,k; int cases; int n = 0; cin>>cases; while( n < cases) { int a, b, c; cin>>a>>b>>c; int res = 0; if((b+c)*2 >= a) res += a/2 + (b+c-a/2+a%2+1)/2; else res += (b+c) + (a - 2*(b+c) + 2)/3; cout<<"Case "<<(n+1)<<": "<<res<<endl; n++; } //system("pause"); return 0; }
- B Buy Sticks
- Buy Sticks
- HDU 3573 Buy Sticks 贪心
- HDU 3573 Buy Sticks 贪心--利用率
- hdu 3573 Buy Sticks(数学)
- (Uva)Buy or Build(B)
- HDU 3573 Buy Sticks 解题报告(贪心)
- Sticks
- sticks
- sticks
- sticks
- Sticks
- sticks
- Sticks
- Sticks
- Sticks
- Sticks
- Sticks
- 全文检索、数据挖掘、推荐引擎系列5---文章术语向量表示法
- hdu3954线段树--4
- Oracle数据导入导出imp/exp命令 10g以上expdp/impdp命令
- OpenCV Tutorial 1 - Chapters 1 and 2
- cxf介绍study
- B Buy Sticks
- 总序
- OpenCart: 架构概览
- 在 .NET 应用程序上运行 Rational PurifyPlus
- hibernate的url加入存入数据库时的编码
- OpenCV Tutorial 2 - Chapter 3
- ubuntu 下连接iSCSI Volume
- struts jasperreport 错误解决
- CVE2011-0065-Mozilla Firefox3.6.16 mChannel use after free vulnerability