BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯
题目
1739: [Usaco2005 mar]Space Elevator 太空电梯
Time Limit: 5 Sec Memory Limit: 64 MB
Description
The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) different types of blocks with which to build the tower. Each block of type i has height h_i (1 <= h_i <= 100) and is available in quantity c_i (1 <= c_i <= 10). Due to possible damage caused by cosmic rays, no part of a block of type i can exceed a maximum altitude a_i (1 <= a_i <= 40000). Help the cows build the tallest space elevator possible by stacking blocks on top of each other according to the rules.
Input
* Line 1: A single integer, K * Lines 2..K+1: Each line contains three space-separated integers: h_i, a_i, and c_i. Line i+1 describes block type i.
Output
* Line 1: A single integer H, the maximum height of a tower that can be built
Sample Input
7 40 3
5 23 8
2 52 6
Sample Output
从底部开始,先放3个方块2,之后3个方块1,接下来6个方块3.不能把3个方块1堆到4个方
块2上,因为这样最高的方块1的顶部高度超过了40.
HINT
Source
题解
Orz考完小四门的期中考试,来刷刷水题愉悦一下身心!Orz坑爹的生物一共75分钟竟然70道选择题一堆大题,我还好几周没去,呵呵~好的,这道题目其实就是做n遍有限背包~
代码
/*Author:WNJXYK*/
#include<cstdio>
#include<algorithm>
using namespace std; struct Node{
int c;
int h;
int a;
};
Node k[];
bool f[];
bool cmp(Node a,Node b){
if (a.a<b.a)return true;
return false;
}
int n;
int main(){
scanf("%d",&n);
for (int i=;i<=n;i++) scanf("%d%d%d",&k[i].h,&k[i].a,&k[i].c);
f[]=true;
sort(k+,k+n+,cmp);
for (int i=;i<=n;i++){
for (int h=k[i].a;h>=;h--){
for (int j=;j<=k[i].c&&k[i].h*j+h<=k[i].a;j++){
f[k[i].h*j+h]=f[k[i].h*j+h]||f[h];
}
}
}
int Ans=;
for (int i=;i>=;i--)
if (f[i]){
Ans=i;
break;
}
printf("%d\n",Ans);
return ;
}
BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯的更多相关文章
- BZOJ1739: [Usaco2005 mar]Space Elevator 太空电梯
n<=400个东西,每个东西有高度<=100,这种东西在堆放过程中不得超过的最大高度<=40000,以及每个东西的个数<=10,求最高能堆多高. 算了下背包复杂度不太对然后开了 ...
- BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )
一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 ...
- BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛
Description 约翰的牛们非常害怕淋雨,那会使他们瑟瑟发抖.他们打算安装一个下雨报警器,并且安排了一个撤退计划.他们需要计算最少的让所有牛进入雨棚的时间. 牛们在农场的F(1≤F≤200 ...
- BZOJ 1682: [Usaco2005 Mar]Out of Hay 干草危机
Description 牛们干草要用完了!贝茜打算去勘查灾情. 有N(2≤N≤2000)个农场,M(≤M≤10000)条双向道路连接着它们,长度不超过10^9.每一个农场均与农场1连通.贝茜要走遍每一 ...
- bzoj:1681 [Usaco2005 Mar]Checking an Alibi 不在场的证明
Description A crime has been comitted: a load of grain has been taken from the barn by one of FJ's c ...
- BZOJ 1680 [Usaco2005 Mar]Yogurt factory:贪心【只用考虑上一个】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1680 题意: 在接下来的n周内,第i周生产一吨酸奶的成本为c[i],订单为y[i]吨酸奶. ...
- bzoj 1680: [Usaco2005 Mar]Yogurt factory【贪心】
贪心,一边读入一边更新mn,用mn更新答案,mn每次加s #include<iostream> #include<cstdio> using namespace std; in ...
- bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机【并查集+二分】
二分答案,把边权小于mid的边的两端点都并起来,看最后是否只剩一个联通块 #include<iostream> #include<cstdio> using namespace ...
- BZOJ 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 贪心 + 问题转化
Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...
随机推荐
- 浅谈Hash函数
什么是hash函数: hash函数也可以翻译成“散列”函数,一般就使用音译“哈希”函数,简单的说哈希函数是对任意长度的输入进行的压缩映射,所谓的压缩映射顾名思义,输出通常来说要比输入短,并且得到的输出 ...
- css如此强大你知道吗
看个这个大神纯 CSS 绘制<辛普森一家>人物头像我惊呆了,css如此牛x <div id="wrap"> <div class="cont ...
- 汉化testlink
testlink版本:1.9.13 1.登录testlink后,打开my setting(左上角小人人) 2.Locale 选择chinese,然后点击save 3.over,汉化完毕
- halcon与C#混合编程
halcon源程序: dev_open_window(0, 0, 512, 512, 'black', WindowHandle)read_image (Image, 'C:/Users/BadGuy ...
- pyVmomi入门
简要说明 pyVmomi is the Python SDK for the VMware vSphere API that allows you to manage ESX, ESXi, and v ...
- 剑指offer——从尾到头打印链表节点的值
输入一个链表,从尾到头打印链表每个节点的值. 输入描述:输入为链表的表头 输出描述:输出为需要打印的“新链表”的表头 一.问题分析 初拿到这个题目时,这应该是考察单向链表这一数据结构.单向链表的遍历总 ...
- 常用CSS HACK
常用CSS HACK IE6 3像素bug和双边距bug一样的经典 现象: IE6下浮动元素和不浮动元素之间会有3px间隙(3px bug,div.float-left + div.float-non ...
- Qt项目管理(33个规则)
2016-06-20 花莫弦 小小杂货铺LY 一.qmake的介绍 qmake是Trolltech公司创建的用来为不同的平台和编译器书写Makefile的工具. 手写Makefile是比较困难并且容易 ...
- HDU 5054 Alice and Bob
#include <cstdio> int main(){ int n,m,x,y; while(~scanf("%d%d%d%d",&n,&m,&am ...
- Intro to Computer Science Class Online (CS101) - Udacity
Intro to Computer Science Class Online (CS101) - Udacity Building a Search Engine