博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 3573(数学+贪心)
阅读量:5243 次
发布时间:2019-06-14

本文共 2017 字,大约阅读时间需要 6 分钟。

Buy Sticks

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 868    Accepted Submission(s): 392

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.
 

 

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
2 3 1 1 4 2 2
 

 

Sample Output
Case 1: 2 Case 2: 3
 

 

Author
imyourgod (Special Thanks : crackerwang & Louty)
 

 

Source
 
题意:需要 x 根20cm,y根 28cm,z根 32cm,问最少需要多少根 75 cm的木棍才可以都分出来?
题解:贪心的去选,先选3根的,选不了了才能选2根的,最后如果还有剩才能选一根的.
这些情况分别是
20 20 28
20 20 32
20 20 20
32 28
28 28
32 32
20
28
32
#include 
#include
#include
#include
#include
#include
#define LL long longusing namespace std;int main(){ int tcase,t = 1; scanf("%d",&tcase); while(tcase--) { int x,y,z; scanf("%d%d%d",&x,&y,&z); int ans = 0,a,b,c; if(x>=2&&y>=1){ /// 20 20 28 a = x/2,b=y; c = min(a,b); x=x-2*c,y=y-c; ans+=c; } if(x>=2&&z>=1){ ///20 20 32 a = x/2,b = z; c = min(a,b); x=x-2*c,z=z-c; ans+=c; } if(x>=3){ ///20 20 20 a = x/3; x = x%3; ans+=a; } if(y>=1&&z>=1){ ///28 32 c = min(y,z); ans+=c; y-=c; z-=c; } if(y>=2){ ///28 28 c = y/2; y = y%2; ans+=c; } if(z>=2){ ///32 32 c = z/2; z = z%2; ans+=c; } if(x||y||z) ans++; printf("Case %d: %d\n",t++,ans); } return 0;}

 

转载于:https://www.cnblogs.com/liyinggang/p/5917865.html

你可能感兴趣的文章
实验四
查看>>
Elastic Stack-Elasticsearch使用介绍(三)
查看>>
MacOS copy图标shell脚本
查看>>
第八章 方法
查看>>
国外常见互联网盈利创新模式
查看>>
Oracle-05
查看>>
linux grep 搜索查找
查看>>
Not enough free disk space on disk '/boot'(转载)
查看>>
android 签名
查看>>
堆 栈
查看>>
Kth Smallest Element in Unsorted Array
查看>>
vue项目中使用百度统计
查看>>
android:scaleType属性
查看>>
SuperEPC
查看>>
RBAC用户角色权限设计方案
查看>>
thymeleaf
查看>>
CentOS7安装iptables防火墙
查看>>
mysql-5.7 innodb 的并行任务调度详解
查看>>
shell脚本
查看>>
Upload Image to .NET Core 2.1 API
查看>>