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. 洛谷 P2659 美丽的序列 解题报告

    P2659 美丽的序列 题目背景 GD是一个热衷于寻求美好事物的人,一天他拿到了一个美丽的序列. 题目描述 为了研究这个序列的美丽程度,GD定义了一个序列的"美丽度"和" ...

  2. 【数学】【P5077】 Tweetuzki 爱等差数列

    Description Tweetuzki 特别喜欢等差数列.尤其是公差为 \(1\) 且全为正整数的等差数列. 显然,对于每一个数 \(s\),都能找到一个对应的公差为 \(1\) 且全为正整数的等 ...

  3. bzoj 1588 平衡树 splay

    1588: [HNOI2002]营业额统计 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 15446  Solved: 6076[Submit][Sta ...

  4. AI技术说:人工智能相关概念与发展简史

    作为近几年的一大热词,人工智能一直是科技圈不可忽视的一大风口.随着智能硬件的迭代,智能家居产品逐步走进千家万户,语音识别.图像识别等AI相关技术也经历了阶梯式发展.如何看待人工智能的本质?人工智能的飞 ...

  5. 通过循环判断size()清理queue的问题

    今天犯了个二逼问题,我想清理一个queue里对象,用了以下方法: ;i<objQueue.size();++i) { T* p_obj = objQueue.front(); delete p_ ...

  6. 跟我一起写Makefile(六)

    使用条件判断—————— 使用条件判断,可以让make根据运行时的不同情况选择不同的执行分支.条件表达式可以是比较变量的值,或是比较变量和常量的值. 一.示例 下面的例子,判断$(CC)变量是否“gc ...

  7. RabbitMQ的原理和使用

    转载:RabbitMQ从入门到精通 转载:轻松搞定RabbitMQ 转载:RabbitMQ Java入门教程 一.RabbitMQ AMQP,即Advanced Message Queuing Pro ...

  8. Codeforces 221 A. Little Elephant and Function

    A. Little Elephant and Function time limit per test 2 seconds memory limit per test 256 megabytes in ...

  9. 树的性质和dfs的性质 Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E

    http://codeforces.com/contest/782/problem/E 题目大意: 有n个节点,m条边,k个人,k个人中每个人都可以从任意起点开始走(2*n)/k步,且这个步数是向上取 ...

  10. 课程设计——利用信号量实现生产者-消费者问题(java)

    package cn.Douzi.ProductConsume; import java.util.LinkedList; import java.util.Queue; import java.ut ...