Cow Acrobats
来源:互联网 发布:asp.net 微商城源码 编辑:程序博客网 时间:2024/05/20 05:11
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.
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.
* 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.
* Lines 2..N+1: Line i+1 describes cow i with two space-separated integers, W_i and S_i.
* Line 1: A single integer, giving the largest risk of all the cows in any optimal ordering that minimizes the risk.
310 32 53 3
2
OUTPUT DETAILS:
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.
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.
按重量和力量的总和排序,大的在下面,然后循环每个牛看他承受的重量
代码:
#include<iostream>#include<string>#include<cstdio>#include<algorithm>#include<cmath>#include<iomanip>#include<queue>#include<cstring>#include<map>using namespace std;typedef long long ll;#define pi acos(-1.0)#define inf 0x3f3f3f#define M 50005struct node{ll w;ll s;}cow[100006];bool cmp(node a,node b){ return a.s+a.w<b.s+b.w;}int main(){ ios::sync_with_stdio(false); int n,i; while(cin>>n) { for(i=0;i<n;i++) cin>>cow[i].w>>cow[i].s; if(n==1){cout<<-cow[0].s<<endl;continue;} sort(cow,cow+n,cmp); ll t=0,res=-inf; for(i=0;i<n;i++) { if(t-cow[i].s>res) res=t-cow[i].s; t+=cow[i].w; } cout<<res<<endl; } return 0;}
阅读全文
1 0
- Cow Acrobats
- 1644 Cow Acrobats TZC
- poj-3045 Cow Acrobats
- POJ 3045 Cow Acrobats
- POJ 3045-Cow Acrobats
- POJ-3045-Cow Acrobats
- POJ Cow Acrobats
- POJ 3045 Cow Acrobats
- poj 3045 Cow Acrobats
- POJ 3045 Cow Acrobats
- poj 3045 Cow Acrobats
- POJ3045 Cow Acrobats (贪心)
- [贪心]poj3045 Cow Acrobats
- POJ3045 Cow Acrobats(贪心)
- POJ3045 Cow Acrobats(贪心)
- POJ3045--Cow Acrobats
- POJ-3045Cow Acrobats
- POJ3045-Cow Acrobats
- android__shape 圆角矩形 圆环画法
- 单链表逆转、字符串按单词逆转
- Java 并发基础
- 实现一个clone函数并可以对js中的5种主要数据类型进行值复制
- 线段树基础与模板与简单应用
- Cow Acrobats
- qt+ffmpeg仿格式工厂
- 借助AMD来解决HTML5游戏开发中的痛点
- RxJava2总结之操作详解(三)
- leetcod
- wchar_t 和 char16_t, char32_t的使用方法 ——C++
- css3-响应式设计
- Emulator: libGL error: unable to load driver: i965_dri.so
- Mysql中关于Could not retrieve transation read-only status server