Cow Acrobats
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3686   Accepted: 1428

Description

Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. Their hoofed feet prevent them from tightrope walking and swinging from the trapeze (and their last attempt at firing a cow out 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

* Line 1: A single line with the integer N. 
* Lines 2..N+1: Line i+1 describes cow i with two space-separated integers, W_i and S_i. 

Output

* Line 1: A single integer, giving the largest risk of all the cows in any optimal ordering that minimizes the risk.

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(贪心)的更多相关文章

  1. POJ 3045 Cow Acrobats (贪心)

    POJ 3045 Cow Acrobats 这是个贪心的题目,和网上的很多题解略有不同,我的贪心是从最下层开始,每次找到能使该层的牛的风险最小的方案, 记录风险值,上移一层,继续贪心. 最后从遍历每一 ...

  2. [USACO2005][POJ3045]Cow Acrobats(贪心)

    题目:http://poj.org/problem?id=3045 题意:每个牛都有一个wi和si,试将他们排序,每头牛的风险值等于前面所有牛的wj(j<i)之和-si,求风险值最大的牛的最小风 ...

  3. poj3045 Cow Acrobats (思维,贪心)

    题目: poj3045 Cow Acrobats 解析: 贪心题,类似于国王游戏 考虑两个相邻的牛\(i\),\(j\) 设他们上面的牛的重量一共为\(sum\) 把\(i\)放在上面,危险值分别为\ ...

  4. 【POJ - 3045】Cow Acrobats (贪心)

    Cow Acrobats Descriptions 农夫的N只牛(1<=n<=50,000)决定练习特技表演. 特技表演如下:站在对方的头顶上,形成一个垂直的高度. 每头牛都有重量(1 & ...

  5. POJ3045 Cow Acrobats 2017-05-11 18:06 31人阅读 评论(0) 收藏

    Cow Acrobats Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4998   Accepted: 1892 Desc ...

  6. BZOJ1629: [Usaco2007 Demo]Cow Acrobats

    1629: [Usaco2007 Demo]Cow Acrobats Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 601  Solved: 305[Su ...

  7. POJ3045 Cow Acrobats —— 思维证明

    题目链接:http://poj.org/problem?id=3045 Cow Acrobats Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  8. POJ-3045 Cow Acrobats (C++ 贪心)

    Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away a ...

  9. 【POJ3045】Cow Acrobats(贪心)

    BUPT2017 wintertraining(16) #4 B POJ - 3045 题意 n(1 <= N <= 50,000) 个牛,重wi (1 <= W_i <= 1 ...

随机推荐

  1. Svn入门

    1.建立svn仓库 ›    命令svnadmin create 仓库名称,如:进入命令行窗口,切换到Svn安装目录下,输入如下命令:svnadmin create F:\software\repos ...

  2. 基于jQuery带标题的图片3D切换焦点图

    今天给大家分享一款基于jQuery带标题的图片3D切换焦点图.这款焦点图适用浏览器:IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗. 实现的代码. htm ...

  3. 上星期IOS的一个面试题。

    美丽说面试题 1,IOS是怎样进行内存管理的,什么是ARC. 2,声明Property时,assign,nonatomic,readonly,retain,copy(各什么意思,括号里没打印出来,我猜 ...

  4. JAVA并发,线程工厂及自定义线程池

    package com.xt.thinks21_2; import java.util.concurrent.ExecutorService; import java.util.concurrent. ...

  5. Apache配置支持include

    Apache配置支持include 什么是SSI? SSI是英文Server Side Includes的缩写,翻译成中文就是服务器端包含的意思.从技术角度上说,SSI就是HTML文件中,可以通过注释 ...

  6. DINOR闪存知识

    闪速存储器(Flash Memory)是一类非易失性存储器NVM(Non-Volatile Memory)即使在供电电源关闭后仍能保持片内信息:而诸如DRAM.SRAM这类易失性存储器,当供电电源关闭 ...

  7. 通过一个模拟程序让你明白WCF大致的执行流程

    原文http://www.cnblogs.com/artech/archive/2011/12/07/wcf-how-to-work.html 在<通过一个模拟程序让你明白ASP.NET MVC ...

  8. 开源搜索技术—Lucene、Solr

    Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,即它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查询引擎和索引引 ...

  9. jquery submit()不能提交表单的解决方法

    <form id="form" method="get"> <input type="text" name="q ...

  10. 基于视觉的Web页面分页算法VIPS的实现源代码下载

    基于视觉的Web页面分页算法VIPS的实现源代码下载 - tingya的专栏 - 博客频道 - CSDN.NET 基于视觉的Web页面分页算法VIPS的实现源代码下载 分类: 技术杂烩 2006-04 ...