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 ...
随机推荐
- python is 和 == 和=
Python中有很多运算符,今天我们就来讲讲is和==两种运算符在应用上的本质区别是什么. 在讲is和==这两种运算符区别之前,首先要知道Python中对象包含的三个基本要素,分别是:id(身份标识) ...
- spingmvc项目根路径访问不到
问题: 如何改mvc中项目的欢迎页,或者叫做根路径 一个东西快弄完了,就剩下一个问题,应该是个小问题.就是mvc项目的欢迎页,怎么给改下呢 访问根路径http://localhost/demo 怎么都 ...
- devexpress 如何读demo源码 总结
对于初学这个庞大的控件集合的程序猿来讲应该是有些难度的.今天就devexpress demo 里边一些东西就本人的所学做一下引导吧. dev 有个帮助文件 DevExpress 中文帮助文档 和每个 ...
- ftp中ftpClient类的API
org.apache.commons.NET.ftp Class FTPClient类FTPClient java.lang.Object java.lang.Object继承 org.apache ...
- html与css关系
1.html是网页的内容的载体 内容是作者发在页面想让用户浏览的信息,包括文字,图片,视频等 2.css样式是表现 像网页的外衣,比如标题字体的变化,颜色的变化,背景颜色,边框等,所有这些都是用来改变 ...
- 5F - Coin Change
Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make c ...
- Win32消息循环机制等【转载】http://blog.csdn.net/u013777351/article/details/49522219
Dos的过程驱动与Windows的事件驱动 在讲本程序的消息循环之前,我想先谈一下Dos与Windows驱动机制的区别: DOS程序主要使用顺序的,过程驱动的程序设计方法.顺序的,过程驱动的程序有一个 ...
- dataTables的学习笔记 -- 未开启服务器数据模式
官方网站:http://www.datatables.net/ (1)未开启服务器数据模式(即"bServerSide" : false),数据会从后台直接全部获取,然后在前台全部 ...
- 如何查看api项目接口
http://www.api.com/Api/Page/index/?format_type=json&api_cate=cms&ma=8026
- macOS X Mount NFS Share / Set an NFS Client
last updated November 3, 2018 in CategoriesLinux, Mac OS X, UNIX How do I access my enterprise NAS s ...