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 ...
随机推荐
- 创建以及加载模块【nodejs第四篇】
建立两个文件,文件一createModule.js ,文件二main.js createModule.js的代码,主要用于创建一个模块 /** * Created by Administrator o ...
- JavaSE复习日记 : 抽象类
/* * 抽象类 * 抽象: * 面向对象的三大核心思想; * 封装: 封装,ppp是封装的一部分 * 继承; * 多态: 父类的引用指向子类的对象 * 引用: 是指一个引用型变量 * 有哪些变量? ...
- codeforces 540D 概率dp
传送门 大概可以这样理解, 一开始有r个石头, p个布, s个剪刀, 每一天有其中的两个相遇, 如果两个是相同的种类, 什么都不会发生, 否则的话有一个会挂掉, 问最后每一种生存的概率. dp[i][ ...
- :last-child的诡异的问题!!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- setFocus一定要写在setLayout设置的后面,否则不起作用——使用setFocusPolicy为控件设置不同的焦点策略:Tab焦点,Click焦点,Wheel焦点和没有焦点
QLineEdit* pEditor = new QLineEdit(m_strText); pEditor->resize(.......); pEditor->move(. ...
- 如何使用 Android Studio 的 git hub 功能
How to use GitHub with Android Studio This article will explain how to use GitHub with Android Studi ...
- linux环境变量配置总结
LD_LIBRARY_PATH: 动态库的查找路径设置:方法一: export LD_LIBRARY_PATH=LD_LIBRARY_PATH:/XXX 但是登出后就失效方法二: 修改~/.bash ...
- Windows Azure 自动伸缩已内置
WindowsAzure平台提供的主要优点之一是能够在有需要时快速缩放云中的应用程序以响应波动.去年7月以前,您必须编写自定义脚本或使用其他工具(如Wasabi或MetricsHub)来启用自动 ...
- Mysql 学习记录
( xampp 的mysql 与 直接用 dnf 安装的 mysql 有冲突! ) 1. 数据库基本知识: 一张表的行 又称为 记录 一张表的列 又称为 字段 表结构:所有字段,规定了你的每一条记录所 ...
- linux下安装python3.3.4
下载安装包 # wget http://www.python.org/ftp/python/3.3.4/Python-3.3.4.tgz 解压 # tar -xzvf Python-3.3.4.tgz ...