POJ3045--Cow Acrobats(theory proving)
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.
因此,如果A在上,B在下,则有:
A: Ra = S + Wb - Xa;
B: Rb = S - Xb;
反之如下:
A: Ra = S - Xa;
B: Rb = S + Wa - Xb;
如果我们定义一方案好于而方案则有:
S + Wb - Xa < S + Wa - Xb;
则: Wa + Xa < Wb + Xb;
#include<iostream>
#include<algorithm>
using namespace std;
struct Cow{
int weight;
int strength;
bool operator<(const Cow& other)const{
return other.weight+other.strength<weight+strength;
}
}cows[];
int main(){
int n;
cin>>n;
int total=;
for(int i=;i<n;i++){
cin>>cows[i].weight>>cows[i].strength;
total+=cows[i].weight;
}
sort(cows,cows+n);
int m=-INT_MAX;
for(int i=;i<n;i++){
total-=cows[i].weight;
m=max(m,total-cows[i].strength);
}
cout<<m<<endl;
return ;
}
POJ3045--Cow Acrobats(theory proving)的更多相关文章
- poj3045 Cow Acrobats (思维,贪心)
题目: poj3045 Cow Acrobats 解析: 贪心题,类似于国王游戏 考虑两个相邻的牛\(i\),\(j\) 设他们上面的牛的重量一共为\(sum\) 把\(i\)放在上面,危险值分别为\ ...
- POJ3045 Cow Acrobats 2017-05-11 18:06 31人阅读 评论(0) 收藏
Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4998 Accepted: 1892 Desc ...
- 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(二分最大化最小值)
https://vjudge.net/problem/POJ-3045 读题后提取到一点:例如对最底层的牛来说,它的崩溃风险=所有牛的重量-(底层牛的w+s),则w+s越大,越在底层. 注意范围lb= ...
- POJ3045 Cow Acrobats
题意 Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join t ...
- [USACO2005][POJ3045]Cow Acrobats(贪心)
题目:http://poj.org/problem?id=3045 题意:每个牛都有一个wi和si,试将他们排序,每头牛的风险值等于前面所有牛的wj(j<i)之和-si,求风险值最大的牛的最小风 ...
- 【POJ - 3045】Cow Acrobats (贪心)
Cow Acrobats Descriptions 农夫的N只牛(1<=n<=50,000)决定练习特技表演. 特技表演如下:站在对方的头顶上,形成一个垂直的高度. 每头牛都有重量(1 & ...
- BZOJ1629: [Usaco2007 Demo]Cow Acrobats
1629: [Usaco2007 Demo]Cow Acrobats Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 601 Solved: 305[Su ...
随机推荐
- pyton random 模块
import random print(random.random())#(0,1)----float 大于0且小于1之间的小数 print(random.randint(1,3)) #[1,3] 大 ...
- 如何提高php应用的性能?
1. 如果能将类的方法定义成static,就尽量定义成static,它的速度会提升将近4倍.2.$row[’id’] 的速度是$row[id]的7倍.3.echo 比 print快,并且使用echo的 ...
- C# 一个数组未赋值引发的错误
在电脑前又是一天,后来脑子也糊里糊涂,可能是基础还不牢固,设置断点,找了找问题才发现数组定义出了问题, 我是这样定义数组的,string[] auths ; string auths=new stri ...
- 27.MySQL备份与恢复
27.备份与恢复27.1 备份/恢复策略考虑因素:备份表的存储引擎(事务性or非事务性):全备份or增量备份用复制做异地备份定期备份,考虑恢复时间确保mysql打开log-bin,有了BINLOG,M ...
- C# 获取 存储过程 返回值
C#获取存储过程的返回值,这一方法,总是容易忘,今天给贴出来,以方便下次使用 存储过程: CREATE PROCEDURE [dbo].[Proc_GetInfo] ), ) out ...
- BZOJ1233 干草堆 - 单调队列优化DP
问题描述: 若有干个干草, 分别有各自的宽度, 要求将它们按顺序摆放, 并且每层的宽度不大于 它的下面一层 , 求最多叠几层 题解: zkw神牛证明了: 底边最短, 层数最高 证明: ...
- Python之路(第三篇):Python基本数据类型字符串(二)
一.基本数据类型1.字符串 str字符串方法介绍(二)a --expandtabs( ) expandtabs( ) 把字符串中的 tab 符号('\t')转为空格参数默认为8,注意字符串原有的空格也 ...
- [ ZooKeeper]ZooKeeper 的功能和原理
Zookeeper功能简介: ZooKeeper 是一个开源的分布式协调服务,由雅虎创建,是 Google Chubby 的开源实现.分布式应用程序可以基于 ZooKeeper 实现诸如数据发布/订阅 ...
- .net使用NPOI的XSSFWorkbook进行web开发中导出Excel
之前也使用过NPOI导出excel,这次是因为在导出的excel里新增了几个列,正好超出了255的限制,所以又要改了. 今天主要出了4个问题: 1. Invalid column index (256 ...
- apache反向代理设置
为了方便在内网测试微信接口API <VirtualHost *:80> ServerName wx.abc.com ProxyPreserveHost on ProxyPass / htt ...