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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define LL long long
using namespace std;
int main()
{
int tcase,t = ;
scanf("%d",&tcase);
while(tcase--)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
int ans = ,a,b,c;
if(x>=&&y>=){ /// 20 20 28
a = x/,b=y;
c = min(a,b);
x=x-*c,y=y-c;
ans+=c;
}
if(x>=&&z>=){ ///20 20 32
a = x/,b = z;
c = min(a,b);
x=x-*c,z=z-c;
ans+=c;
}
if(x>=){ ///20 20 20
a = x/;
x = x%;
ans+=a;
}
if(y>=&&z>=){ ///28 32
c = min(y,z);
ans+=c;
y-=c;
z-=c;
}
if(y>=){ ///28 28
c = y/;
y = y%;
ans+=c;
}
if(z>=){///32 32
c = z/;
z = z%;
ans+=c;
}
if(x||y||z) ans++;
printf("Case %d: %d\n",t++,ans);
}
return ;
}

hdu 3573(数学+贪心)的更多相关文章

  1. hdu 5747(数学,贪心)

    Aaronson Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  2. HDU 5984 数学期望

    对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...

  3. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  4. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  5. hdu 4091 数学思维题贪心

    /* 参看博客地址:http://blog.csdn.net/oceanlight/article/details/7857713 重点是取完最优的后剩余的rest=n%lcm+lcm;中性价比小的数 ...

  6. hdu 2037简单贪心--活动安排问题

    活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...

  7. HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  8. HDU 4310 Hero (贪心算法)

    A - Hero Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  9. hdu 4268 multiset+贪心

    Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...

随机推荐

  1. windows下载执行命令大全

      1.bitsadmin命令(只能命令下载到指定路径上,win7以上): bitsadmin /transfer myDownLoadJob /download /priority normal & ...

  2. makefile使用笔记(二)变量

    By francis_hao    Oct 30,2017   makefile中可以使用变量,变量有多种类型,下面分别介绍 简单变量 简单变量的命名规则和c语言一致. 给变量赋值就表示创建了这个变量 ...

  3. Codeforces Round #338 (Div. 2) D 数学

    D. Multipliers time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. stout代码分析之一:Duration类

    Duration类用于表示时间长度,可精确到纳秒. 代码实现在duration.hpp中,测试代码:duration_tests.cpp 相关api如下: parse, 将字符串转化成Duration ...

  5. 正则(?is)

    Q:经常看见的正则前面的 (?i) (?s) (?m) (?is) (?im) 是什么意思?A: 称为内联匹配模式,通常用内联匹配模式代替使用枚举值RegexOptions指定的全局匹配模式,写起来更 ...

  6. NOIP模拟6

    期望得分:100+100+100=300 实际得分:0+100+90=190 T1 superman 二分给每条边加多少,判断是否存在负环 #include<queue> #include ...

  7. Python学习笔记(四十三)virtualenv (创建一套“隔离”的Python运行环境)

    摘抄自:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432712108 ...

  8. 桥接模式_NAT模式_仅主机模式_模型图.ziw

      2017年1月12日, 星期四 桥接模式_NAT模式_仅主机模式_模型图   null

  9. php每天自动备份数据库

    php每天自动备份数据库 windows中如何添加计划任务? 前提:添加windows计划任务,每天打开备份数据库的页面.1.打开http://localhost/thinkphp3.2/index. ...

  10. 【HDU】6110 路径交(2017百度之星) 线段树+RMQ-LCA+树链的交

    [题目]2017"百度之星"程序设计大赛 - 初赛(A) [题意]给定n个点的带边权树,m条编号1~m的路径,Q次询问编号区间[L,R]所有链的交集的长度.n<=500000 ...