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. JAVA导出Excel(支持多sheet)

    一.批量导出: /** * * @Title: expExcel * @Description: 批量导出客户信息 * @param @param params * @param @param req ...

  2. (转)ARC指南 - strong、weak指针

    一.简介 ARC是自iOS 5之后增加的新特性,完全消除了手动管理内存的烦琐,编译器会自动在适当的地方插入适当的retain.release.autorelease语句.你不再需要担心内存管理,因为编 ...

  3. Codeforces 894.D Ralph And His Tour in Binary Country

    D. Ralph And His Tour in Binary Country time limit per test 2.5 seconds memory limit per test 512 me ...

  4. C++并发编程 thread

    std::thread C++11在标准库中为多线程提供组件, 使用线程需要包含头文件 thread, 其命名空间为 std. 启动新线程 每个进程至少有一个线程: 执行main()函数的线程, 其余 ...

  5. C/C++ string.h头文件小结

    http://note.youdao.com/noteshare?id=cff515f7b683f579d22f17b54b960e2a

  6. linux根据进程pid查看进程详细信息

    http://note.youdao.com/noteshare?id=af2fdd34e3adfacda2d34706e16e5045

  7. 分块+deque维护 Codeforces Round #260 (Div. 1) D. Serega and Fun

    D. Serega and Fun time limit per test 4 seconds memory limit per test 256 megabytes input standard i ...

  8. java学习——equals()和==的比较

    equals 方法是 java.lang.Object 类的方法. 下面从两个方面来说明equals()和==的差别:(1)对于字符串变量来说,使用“==”和“equals()”方法比较字符串时,其比 ...

  9. c#开发_Dev的关于XtraGrid的使用(GridControl小结)

    1,增加新行用InitNewRow事件,给新行某字段赋值.后结束编辑. private void grdView_InitNewRow(object sender, DevExpress.XtraGr ...

  10. matlab实现cart(回归分类树)

    作为机器学习的小白和matlab的小白自己参照 python的 <机器学习实战> 写了一下分类回归树,这里记录一下. 关于决策树的基础概念就不过多介绍了,至于是分类还是回归..我说不清楚. ...