POJ --3045--Cow Acrobats(贪心模拟)
| Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
Description
of a cannon met with a dismal failure). Thus, they have decided to practice performing acrobatic stunts.
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<cstdio>
#include<cstring>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
struct node
{
LL w,s;
}cow[100100];
int cmp(node s1,node s2)
{
return s1.s+s1.w>s2.s+s2.w;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
LL temp=0,ans=-INF;
for(int i=0;i<n;i++)
scanf("%d%d",&cow[i].w,&cow[i].s);
sort(cow,cow+n,cmp);
if(n==1) ans=-cow[0].s;
else
{
for(int i=n-1;i>=0;i--)
{
if(temp-cow[i].s>ans)
ans=temp-cow[i].s;
temp+=cow[i].w;
}
}
printf("%lld\n",ans);
}
return 0;
}
POJ --3045--Cow Acrobats(贪心模拟)的更多相关文章
- POJ 3045 Cow Acrobats (贪心)
POJ 3045 Cow Acrobats 这是个贪心的题目,和网上的很多题解略有不同,我的贪心是从最下层开始,每次找到能使该层的牛的风险最小的方案, 记录风险值,上移一层,继续贪心. 最后从遍历每一 ...
- POJ - 3045 Cow Acrobats (二分,或者贪心)
一开始是往二分上去想的,如果risk是x,题目要求则可以转化为一个不等式,Si + x >= sigma Wj ,j表示安排在i号牛上面的牛的编号. 如果考虑最下面的牛那么就可以写成 Si + ...
- poj 3045 Cow Acrobats(二分搜索?)
Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away a ...
- POJ 3045 Cow Acrobats
Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away a ...
- POJ 3045 Cow Acrobats (最大化最小值)
题目链接:click here~~ [题目大意] 给你n头牛叠罗汉.每头都有自己的重量w和力量s,承受的风险数rank就是该牛上面全部牛的总重量减去该牛自身的力量,题目要求设计一个方案使得全部牛里面风 ...
- Cow Acrobats(贪心)
Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3686 Accepted: 1428 Desc ...
- poj 3617 Best Cow Line 贪心模拟
Best Cow Line Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 42701 Accepted: 10911 D ...
- [USACO2005][POJ3045]Cow Acrobats(贪心)
题目:http://poj.org/problem?id=3045 题意:每个牛都有一个wi和si,试将他们排序,每头牛的风险值等于前面所有牛的wj(j<i)之和-si,求风险值最大的牛的最小风 ...
- POJ:1017-Packets(贪心+模拟,神烦)
传送门:http://poj.org/problem?id=1017 Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
- poj 3045 叠罗汉问题 贪心算法
题意:将n头牛叠起来,每头牛的力气 s体重 w 倒下的风险是身上的牛的体重的和减去s 求最稳的罗汉倒下去风险的最大值 思路: 将s+w最大的放在下面,从上往下看 解决问题的代码: #include& ...
随机推荐
- COGS——T 886. [USACO 4.2] 完美的牛栏
http://www.cogs.pro/cogs/problem/problem.php?pid=886 ★★☆ 输入文件:stall4.in 输出文件:stall4.out 简单对比时间 ...
- 洛谷——T P2136 拉近距离
https://www.luogu.org/problem/show?pid=2136 题目背景 我是源点,你是终点.我们之间有负权环. ——小明 题目描述 在小明和小红的生活中,有N个关键的节点.有 ...
- YAML说明
YAML说明 https://www.cnblogs.com/songchaoke/p/3376323.html XML的简化
- servlet调用的几种方式
參见 文库/java/javaEE全新学习教程2.2节 1.通过URL调用 2通过提交表单 3超链接 4 javascript写一个函数,调用这个函数 1,首先在project的WebRoot目录下建 ...
- [ReactVR] Add Shapes Using 3D Primitives in React VR
React VR ships with a handful of 3D primitives. We'll importprimitives like <Sphere/>, <Box ...
- jsoup抓取网页+具体解说
jsoup抓取网页+具体解说 Java 程序在解析 HTML 文档时,相信大家都接触过 htmlparser 这个开源项目.我以前在 IBM DW 上发表过两篇关于 htmlparser 的文章.各自 ...
- atitit。企业组织与软件project的策略 战略 趋势 原则 attilax 大总结
atitit. 企业组织与软件project的策略 战略 趋势 原则 attilax 大总结 1. 战略规划,适当的过度设计 1 2. 跨平台化 1 3. 可扩展性高于一切 1 4. 界面html5化 ...
- 从QQ聊天看交流的有效性
首先让我们看一则约10分钟的QQ群聊天记录.截图例如以下.已经进行了隐私保护. 交流的主体为大二的在校生与刚刚毕业的学长之间的对话,学长參加过培训,在校学弟想了解一下.故有了以下的交流.(从上到下,从 ...
- 【笨木头Lua专栏】基础补充02:函数的几个特别之处
没想到距离上一篇基础补充已经过了1年多了,近期准备捡回Lua,把基础都补补,今天来聊聊Lua的函数吧~ 0.环境 我突然对Lua又大感兴趣的最主要原因是,Cocos Code IDE開始浮出水面了,它 ...
- DGA ngram kmeans+TSNE用于绘图
# -*- coding:utf-8 -*- import sys import re import numpy as np from sklearn.externals import joblib ...