POJ3045 Cow Acrobats —— 思维证明
题目链接:http://poj.org/problem?id=3045
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5713 | Accepted: 2151 |
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 <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e5+; struct node
{
int w, s;
bool operator<(const node &x)const{
return (w+s)<(x.w+x.s);
}
}a[MAXN]; int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
for(int i = ; i<=n; i++)
scanf("%d%d", &a[i].w, &a[i].s);
sort(a+, a++n);
LL ans = -INF, tot = ;
for(int i = ; i<=n; i++)
{
ans = max(ans, tot-a[i].s);
tot += a[i].w;
}
printf("%lld\n", ans);
}
}
POJ3045 Cow Acrobats —— 思维证明的更多相关文章
- 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 ...
- POJ-3045 Cow Acrobats (C++ 贪心)
Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away a ...
- [USACO2005][POJ3045]Cow Acrobats(贪心)
题目:http://poj.org/problem?id=3045 题意:每个牛都有一个wi和si,试将他们排序,每头牛的风险值等于前面所有牛的wj(j<i)之和-si,求风险值最大的牛的最小风 ...
- 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 ...
- 【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 ...
- POJ 3045 Cow Acrobats (贪心)
POJ 3045 Cow Acrobats 这是个贪心的题目,和网上的很多题解略有不同,我的贪心是从最下层开始,每次找到能使该层的牛的风险最小的方案, 记录风险值,上移一层,继续贪心. 最后从遍历每一 ...
随机推荐
- miller_rabin + pollard_rho模版
#include<stdio.h> #include<stdlib.h> #include<time.h> #include<math.h> #incl ...
- 线段树练习5(codevs 4927)
题目描述 Description 有n个数和5种操作 add a b c:把区间[a,b]内的所有数都增加c set a b c:把区间[a,b]内的所有数都设为c sum a b:查询区间[a,b] ...
- HTML 文档之 Head 最佳实践--摘抄
HTML 文档之 Head 最佳实践 story 01-10 阅读 353 收藏 0 收藏 这篇文章整理了作者认可的一些最佳实践,写在这里与各位分享 阅读原文折叠收起 HTML 文档之 Head 最佳 ...
- ORA-01940: cannot drop a user that is currently connected 问题解析
https://www.linuxidc.com/Linux/2012-12/76448.htm
- CPU 内存 硬盘的区别
第一点:CPU 是处理器,内存和硬盘是存储器,受CPU 的控制. 第二点:由于内存的速度很快,在电脑运行的过程中,CPU通常只与内存交换数据,但内存断电数据就会全部丢失,因此电脑使用硬盘作为主要的存 ...
- 问题:typedef char *pstring????
typedef char *pstring; const pstring cstr = 0; //cstr是指向char的常量指针: const pstring *ps; //ps是一个指针,它的对象 ...
- 【Todo】ES6学习
今天部分分享,有一篇PPT,放在这里了 /Users/baidu/Documents/Data/Work/分享资料/ES6大法好.pptx 内容挺丰富的,可以学习.
- BUPT复试专题—寻找变化前01序列(2016)
题目描述 给你一个01序列,HDLC协议处理的话,如果出现连续的5个1会补1个0.例如1111110,会变成11111010. 现在给你一个经过HDLC处理后的01序列,你需要找到HDLC处理之前的0 ...
- git log 查看版本演变历史
1.查看git操作历史 $ git log #git 查看git操作历史 $ git log --oneline #git 简洁的查看git变更记录 $ git log -n4 --onelin ...
- 一种排序(nyoj8)(简单排序)
一种排序 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描写叙述 如今有非常多长方形.每个长方形都有一个编号,这个编号能够反复.还知道这个长方形的宽和长,编号.长.宽都是整数 ...