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 ...
随机推荐
- 匹配图片src正则
preg_match_all('#<img.*?src="([^"]*)"[^>]*>#i', $xstr, $match); /** * 获取图片sr ...
- JS 代码调试经验总结(菜鸟必读)
前言:不知不觉写了很多,希望你能耐心看完这篇文章 任何一个编程者都少不了要去调试代码,不管你是高手还是菜鸟,调试程序都是一项必不可少的工作.一般来说调试程序是在编写代码之后或测试期修改Bug 时进行的 ...
- Hyper-v 安装CentOS
http://www.cnblogs.com/dunitian/p/4976077.html
- Ubuntu14下LAMP环境的安装以及yaf扩展的安装
前段时间在ubuntu下安装了lamp环境,记录一下安装过程方便以后查阅. 安装lamp环境 ① 安装apache sudo apt-get install apache2 系统会弹出如图所示的提示, ...
- C#学习日志 day 1 ------ hello C# !
首先是C#的编译器的安装.这里用vs2013.我用的是Windows 8.1系统,所以安装起来并不难. 双击vs_ultimate.exe 逐步安装就好.这里用校园邮箱在dream spark 上进行 ...
- python,redis简单订阅
python连接redis import redis r =redis.Redis(host='192.168.199.11',port = 6379 ,db = 0) r.publish('chan ...
- Analysis about different methods for reading and writing file in Java language
referee:Java Programming Tutorial Advanced Input & Output (I/O) JDK 1.4+ introduced the so-calle ...
- pl sql 无法解析指定的连接标识符
使用PLSQL Developer时,“ORA-12154: TNS:无法解析指定的连接标识符”问题的一个解决办法< xmlnamespace prefix ="o" ...
- Linux中的IO复用接口简介(文件监视?)
I/O复用是Linux中的I/O模型之一.所谓I/O复用,指的是进程预先告诉内核,使得内核一旦发现进程指定的一个或多个I/O条件就绪,就通知进程进行处理,从而不会在单个I/O上导致阻塞. 在Linux ...
- Java图形化界面设计——容器(JFrame)
Java图形化界面设计——容器(JFrame) 程序是为了方便用户使用的,因此实现图形化界面的程序编写是所有编程语言发展的必然趋势,在命令提示符下运行的程序可以让我们了解java程序的基本知识体系结构 ...