POJ 3045
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 2302 | Accepted: 912 |
Description
The cows aren't terribly creative and have only come up with one acrobatic stunt: standing on top of each other to form a vertical stack of some height. The cows are trying to figure out the order in which they should arrange themselves ithin this stack.
Each of the N cows has an associated weight (1 <= W_i <= 10,000) and strength (1 <= S_i <= 1,000,000,000). The risk of a cow collapsing is equal to the combined weight of all cows on top of her (not including her own weight, of course) minus her strength (so that a stronger cow has a lower risk). Your task is to determine an ordering of the cows that minimizes the greatest risk of collapse for any of the cows.
Input
* Lines 2..N+1: Line i+1 describes cow i with two space-separated integers, W_i and S_i.
Output
Sample Input
3
10 3
2 5
3 3
Sample Output
2
Hint
Put the cow with weight 10 on the bottom. She will carry the other two cows, so the risk of her collapsing is 2+3-3=2. The other cows have lower risk of collapsing.
Source
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; #define maxn 50005 #define INF (1 << 30) struct node {
int w,s;
}; node s[maxn];
int n; bool cmp(node a,node b) {
return (a.w + a.s) < (b.w + b.s);
} int main() { scanf("%d",&n);
for(int i = ; i <= n; ++i) {
scanf("%d%d",&s[i].w,&s[i].s);
} sort(s + ,s + n + ,cmp); int now = ,ans = -INF ;
for(int i = ; i <= n; ++i) {
ans = max(ans,now - s[i].s);
now += s[i].w;
} printf("%d\n",ans); return ; }
POJ 3045的更多相关文章
- POJ 3045 Cow Acrobats (贪心)
POJ 3045 Cow Acrobats 这是个贪心的题目,和网上的很多题解略有不同,我的贪心是从最下层开始,每次找到能使该层的牛的风险最小的方案, 记录风险值,上移一层,继续贪心. 最后从遍历每一 ...
- Greedy:Cow Acrobats(POJ 3045)
牛杂技团 题目大意:一群牛想逃跑,他们想通过搭牛梯来通过,现在定义risk(注意可是负的)为当前牛上面的牛的总重量-当前牛的strength,问应该怎么排列才能使risk最小? 说实话这道题我一开始给 ...
- poj 3045 Cow Acrobats(二分搜索?)
Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away a ...
- POJ 3045 Cow Acrobats
Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away a ...
- POJ - 3045 Cow Acrobats (二分,或者贪心)
一开始是往二分上去想的,如果risk是x,题目要求则可以转化为一个不等式,Si + x >= sigma Wj ,j表示安排在i号牛上面的牛的编号. 如果考虑最下面的牛那么就可以写成 Si + ...
- poj 3045 叠罗汉问题 贪心算法
题意:将n头牛叠起来,每头牛的力气 s体重 w 倒下的风险是身上的牛的体重的和减去s 求最稳的罗汉倒下去风险的最大值 思路: 将s+w最大的放在下面,从上往下看 解决问题的代码: #include& ...
- POJ 3045 Cow Acrobats (最大化最小值)
题目链接:click here~~ [题目大意] 给你n头牛叠罗汉.每头都有自己的重量w和力量s,承受的风险数rank就是该牛上面全部牛的总重量减去该牛自身的力量,题目要求设计一个方案使得全部牛里面风 ...
- 【POJ - 3045】Cow Acrobats (贪心)
Cow Acrobats Descriptions 农夫的N只牛(1<=n<=50,000)决定练习特技表演. 特技表演如下:站在对方的头顶上,形成一个垂直的高度. 每头牛都有重量(1 & ...
- POJ 2456 3258 3273 3104 3045(二分搜索-最大化最小值)
POJ 2456 题意 农夫约翰有N间牛舍排在一条直线上,第i号牛舍在xi的位置,其中有C头牛对牛舍不满意,因此经常相互攻击.需要将这C头牛放在离其他牛尽可能远的牛舍,也就是求最大化最近两头牛之间的距 ...
随机推荐
- 方法:一个简单的读取配置文件.properties的工具类 JAVA
import java.util.ResourceBundle; public class ConfigHelper { private static ConfigHelper instance; p ...
- struts2值栈分析
前段日子对ognl表达式不是很理解,看了几本书上关于ognl表达式的描述后还是感觉很难,前几天学习了struts2中值栈的内容,现在感觉ognl表达式其实很容易. struts2中利用值栈来存储数据, ...
- Ajax乱码问题
Ajax中文乱码问题 1.js代码 var userName=$("#userName").val(); var url = "user/login.action?u ...
- POJ 1285 确定比赛名次
Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委 ...
- unity 多线程
对于客户端来说,好的用户体验,需要保持一个快速响应的用户界面.于是便要求:网络请求.io操作等 开销比较大的操作必须在后台线程进行,从而避免主线程的ui卡顿.(注:协程也是主线程的一部分,进行大量的i ...
- 14.Apache配置
环境: ↗ atl.example.com (192.168.1.101) ↗ www.e ...
- Zedboard VmodCAM PIN Constraint
自己画了一块FMC-VHDCI四层板,外接VmodCAM,接口定义如下 #CAMA PIN CONSTRACT NET "CAMA_D_I[7]" LOC = T17 | IOST ...
- ORACLE 基础知识积累
创建ORACLE 数据库,首先用Sys账号角色为dba进入数据库然后,然后根据创建数据库的表空间,然后创建角色,创建完角色后将表空间的权限授予角色. SQL语句如下: create temporary ...
- 京东sdk商家上架接口调用问题总结(更新中...)
前言: 最近在做商家发布产品,调用京东sdk,发现问题很多,而且还是在我同事的帮助下完成的,摸索中,菜鸟还请高手门多多提携才好,入正题 首先是引用jd的sdk啦,京东sdk中发布商品需要调用一个 36 ...
- phpcms v9 源码解析(3)pc_base::creat_app()
69 return self::load_sys_classs('application'); 在前面我们已经知道了,这个load_sys_classs 静态方法,它加载了P ...