Cow Acrobats(贪心)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3686 | Accepted: 1428 |
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
题解:错的心碎啊,还是代码太弱,会写而wa。。。。重的而且抗压的显然在最下面;
代码:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=100010;
typedef long long LL;
const int inf=1<<29;
struct Node{
LL w,s;
friend bool operator < (Node a,Node b){
return a.w+a.s>b.w+b.s;
}
};
Node dt[MAXN];
int main(){
int N;
while(~scanf("%d",&N)){
for(int i=0;i<N;i++){
scanf("%lld%lld",&dt[i].w,&dt[i].s);
}
sort(dt,dt+N);
LL ans=-inf,temp=0;
if(N==1)ans=-dt[0].s;
for(int i=N-1;i>=0;i--){
if(temp-dt[i].s>ans)ans=temp-dt[i].s;
temp+=dt[i].w;
}
printf("%I64d\n",ans);
} return 0;
}
Cow Acrobats(贪心)的更多相关文章
- POJ 3045 Cow Acrobats (贪心)
POJ 3045 Cow Acrobats 这是个贪心的题目,和网上的很多题解略有不同,我的贪心是从最下层开始,每次找到能使该层的牛的风险最小的方案, 记录风险值,上移一层,继续贪心. 最后从遍历每一 ...
- [USACO2005][POJ3045]Cow Acrobats(贪心)
题目:http://poj.org/problem?id=3045 题意:每个牛都有一个wi和si,试将他们排序,每头牛的风险值等于前面所有牛的wj(j<i)之和-si,求风险值最大的牛的最小风 ...
- poj3045 Cow Acrobats (思维,贪心)
题目: poj3045 Cow Acrobats 解析: 贪心题,类似于国王游戏 考虑两个相邻的牛\(i\),\(j\) 设他们上面的牛的重量一共为\(sum\) 把\(i\)放在上面,危险值分别为\ ...
- 【POJ - 3045】Cow Acrobats (贪心)
Cow Acrobats Descriptions 农夫的N只牛(1<=n<=50,000)决定练习特技表演. 特技表演如下:站在对方的头顶上,形成一个垂直的高度. 每头牛都有重量(1 & ...
- POJ3045 Cow Acrobats 2017-05-11 18:06 31人阅读 评论(0) 收藏
Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4998 Accepted: 1892 Desc ...
- BZOJ1629: [Usaco2007 Demo]Cow Acrobats
1629: [Usaco2007 Demo]Cow Acrobats Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 601 Solved: 305[Su ...
- POJ3045 Cow Acrobats —— 思维证明
题目链接:http://poj.org/problem?id=3045 Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- POJ-3045 Cow Acrobats (C++ 贪心)
Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away a ...
- 【POJ3045】Cow Acrobats(贪心)
BUPT2017 wintertraining(16) #4 B POJ - 3045 题意 n(1 <= N <= 50,000) 个牛,重wi (1 <= W_i <= 1 ...
随机推荐
- Unity StrangeIoc框架 (一)
最近想项目中需要使用这个架构 因此 上网看了很多资料摸索 但是对于初学者来说大多数的资料不是那么容易理解 而且文档也是英文的阅读起来有点吃力 所以记录一下自己阅读的过程 方便以后翻阅和跟我一 ...
- switch_case,&&,||,条件操作符和逗号操作符,循环语句
一.switch-case switch-case语句主要用在多分支条件的环境中,在这种环境中使用if语句会存在烦琐且效率不高的弊端. switch(expression) { case const ...
- JavaScript中的闭包理解
原创文章,转载请注明:JavaScript中的闭包理解 By Lucio.Yang 1.JavaScript闭包 在小学期开发项目的时候,用node.js开发了服务器,过程中遇到了node.js的第 ...
- hadoop搭建杂记:Linux下hadoop的安装配置
VirtualBox搭建伪分布式模式:hadoop的下载与配置 VirtualBox搭建伪分布式模式:hadoop的下载与配置 由于个人机子略渣,无法部署XWindow环境,直接用的Shell来操作, ...
- javascript小练习—记住密码提示框
px/px solid redpxpx]; var oTips = document.getElementById("tips"); oP.onmousemove = functi ...
- Decorators and Wrappers in Python
python代码一贯以优雅,简洁著称,而有时侯反而会让人难以理解,比如说wrapper(或者说decorator),这种方式提高了代码的可重用性,使用起来更简洁方便. 举个例子,比如WebApp常用的 ...
- JAVA的BIT数组
写个小东西,要去重复数字,用到BIT数组,虽然JAVA已经提供了一个BitSet,不过自己手痒,又写了一个简单的 原理就不写了,网上一大堆 import java.util.Iterator; imp ...
- 转: when.js原理和核心实现
这篇文章可以看作是屈屈同学关于when.js的文章<异步编程:When.js快速上手>的续篇. 屈屈的文章中详细介绍了when.js,在这里关于when.js的使用我就不多复述了,大家可以 ...
- 微软提供的虚拟磁盘API
https://msdn.microsoft.com/en-us/library/windows/desktop/dd323684(v=vs.85).aspx https://msdn.microso ...
- 投资新兴市场和细分市场 good
新兴市场对程序员来说,就是一种新的语言.一个新的平台.一套新的框架.新兴市场因为刚刚兴起,所以几乎所有人都在同一个起跑线,特别适合后进者.我认识从一个2011年开始学习iOS开发的同学,他能能力中等, ...