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.

解题报告:

各种乱搞+贪心WA一片,最后按w[i]+s[i]从大到小排序就莫名对了,后来仔细一想还是可靠的,假设A在B上面,那么 \(rist_A=Sum-w_A-w_B-s_A\) 并且交换A,B位置之后上面位置的risk都不变,但是下面的就会变成\(Sum_B-w_A-s_A\),所以贪心策略就是把 \(w_i+s_i\)最大的放在最下面,以此类推

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
const int N=5e4+5;
int w[N],s[N],a[N];
bool comp(int i,int j){
return w[i]+s[i]>w[j]+s[j];
}
void work()
{
int n;ll tot=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&w[i],&s[i]);
a[i]=i;tot+=w[i];
}
sort(a+1,a+n+1,comp);
int ans=-2e9;
for(int i=1;i<=n;i++){
ans=Max(ans,tot-w[a[i]]-s[a[i]]);
tot-=w[a[i]];
}
printf("%d\n",ans);
} int main()
{
work();
return 0;
}

POJ 3045 Cow Acrobats的更多相关文章

  1. POJ 3045 Cow Acrobats (贪心)

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

  2. poj 3045 Cow Acrobats(二分搜索?)

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

  3. POJ - 3045 Cow Acrobats (二分,或者贪心)

    一开始是往二分上去想的,如果risk是x,题目要求则可以转化为一个不等式,Si + x >= sigma Wj ,j表示安排在i号牛上面的牛的编号. 如果考虑最下面的牛那么就可以写成 Si + ...

  4. POJ 3045 Cow Acrobats (最大化最小值)

    题目链接:click here~~ [题目大意] 给你n头牛叠罗汉.每头都有自己的重量w和力量s,承受的风险数rank就是该牛上面全部牛的总重量减去该牛自身的力量,题目要求设计一个方案使得全部牛里面风 ...

  5. POJ3045 Cow Acrobats —— 思维证明

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

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

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

  7. 【POJ3045】Cow Acrobats(贪心)

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

  8. POJ 3045

    Cow Acrobats Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2302   Accepted: 912 Descr ...

  9. BZOJ1629: [Usaco2007 Demo]Cow Acrobats

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

随机推荐

  1. Linux学习--进程创建

    进程创建 在Linux系统下,自己可以创建进程: 当进程执行时,它会被装载进虚拟内存,为程序变量分配空间,并把相关信息添到 task_struct里. 进程内存布局分为四个不同的段: • 文本段,包含 ...

  2. 2017 清北济南考前刷题Day 3 afternoon

    期望得分:100+40+100=240 实际得分:100+40+100=240 将每个联通块的贡献乘起来就是答案 如果一个联通块的边数>点数 ,那么无解 如果边数=点数,那么贡献是 2 如果边数 ...

  3. Something about SeekingJob---TelInterview(电话面试)

    昨天和今天分别收到两次电话面试,有一点小小感悟,遂注之. 作为一枚还未毕业的大三狗来说,我在想,找个实习真的是西天取金,必定要先经历九九八十一难吗(伤心)?所以在这里整理了电话面试遇到的问题: 集合框 ...

  4. VS2013 重装 无法打开项目

    今天遇到的奇葩BUG,耗时我一下午,现在跟大家说道说道. 今天重装系统,让各种开发环境开发工具自然要重装一次,最后装完VS2013,然后刚好客户打电话要改点东西,然后我就双击项目准备打开改,然后奇葩来 ...

  5. JAVA_SE基础——72.自定义线程

    进程 :  正在执行的程序称作为一个进程.  进程负责了内存空间的划分.   问题: windows号称是多任务的操作系统,那么windows是同时运行多个应用程序吗?从宏观的角度: windows确 ...

  6. JAVA_SE基础——19.数组的定义

    数组是一组相关数据的集合,数组按照使用可以分为一维数组.二维数组.多维数组 本章先讲一维数组 不同点: 不使用数组定义100个整形变量:int1,int2,int3;;;;;; 使用数组定义 int ...

  7. 逆向集录_00_不同程序OEP特征总结

    在分析/逆向 程序时,如果事先知道这类程序的一些特征,那将会是事半功倍的: 分析/逆向 程序,和写程序不同,比喻的话:写程序像在作案,分析/逆向 程序就像是在破案,对破案来讲,重在假想和推理: 特征1 ...

  8. 新概念英语(1-143)A walk through the woods

    Lesson 143 A walk through the woods 林中散步 Listen to the tape then answer this question. What was so f ...

  9. java基础总结(1)安装jdk

           卸载java java -version yum remove java yum groupjava java        安装java tar -zxvf jdk-8u60-linu ...

  10. spring-oauth-server实践:客户端和服务端环境搭建

    客户端:http://localhost:8080/spring-oauth-client/index.jsp 服务端:http://localhost:8080/spring-oauth-serve ...