poj3045 Cow Acrobats (思维,贪心)
题目:
解析:
贪心题,类似于国王游戏
考虑两个相邻的牛\(i\),\(j\)
设他们上面的牛的重量一共为\(sum\)
把\(i\)放在上面,危险值分别为\(x_1=sum-s_i\),$ x_2=sum+w_i-s_j\(
把\)j\(放在上面,危险值分别为\)x_3=sum-s_j$, \(x_4=sum+w_j-s_i\)
若把j放在上面更优,则有\(max(x_3,x_4)<max(x_1,x_2)\)
有四种情况
\(x_3<x_1\)
\(x_3<x_2\)
\(x_4<x_1\)
\(x_4<x_2\)
显然的是\(x_3<x_2\),\(x_1>x_4\)
而\(s_i\)和\(s_j\)关系不确定
所以一定有\(w_i+s_i>w_j+w_j\)
按\(w+s\)排序从小到大排序,大的在下面
代码:
很简单
#include <iostream>
#include <algorithm>
#include <cstdio>
#define int long long
using namespace std;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int n;
struct node {
int w, s;
bool operator <(const node &oth) const {
return w + s < oth.w + oth.s;
}
} e[N];
template<class T>inline void read(T &x) {
x = 0; char ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return;
}
signed main() {
read(n);
for (int i = 1; i <= n; ++i) read(e[i].w), read(e[i].s);
sort(e + 1, e + 1 + n);
int sum = 0, ans = -INF;
for (int i = 1; i <= n; ++i) ans = max(ans, sum - e[i].s), sum += e[i].w;
cout << ans << endl;
}
poj3045 Cow Acrobats (思维,贪心)的更多相关文章
- POJ3045 Cow Acrobats —— 思维证明
题目链接:http://poj.org/problem?id=3045 Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- POJ-3045 Cow Acrobats (C++ 贪心)
Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away a ...
- 【POJ - 3045】Cow Acrobats (贪心)
Cow Acrobats Descriptions 农夫的N只牛(1<=n<=50,000)决定练习特技表演. 特技表演如下:站在对方的头顶上,形成一个垂直的高度. 每头牛都有重量(1 & ...
- POJ3045 Cow Acrobats 2017-05-11 18:06 31人阅读 评论(0) 收藏
Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4998 Accepted: 1892 Desc ...
- 【POJ3045】Cow Acrobats(贪心)
BUPT2017 wintertraining(16) #4 B POJ - 3045 题意 n(1 <= N <= 50,000) 个牛,重wi (1 <= W_i <= 1 ...
- [USACO2005][POJ3045]Cow Acrobats(贪心)
题目:http://poj.org/problem?id=3045 题意:每个牛都有一个wi和si,试将他们排序,每头牛的风险值等于前面所有牛的wj(j<i)之和-si,求风险值最大的牛的最小风 ...
- 【BZOJ】1629: [Usaco2007 Demo]Cow Acrobats(贪心+排序)
http://www.lydsy.com/JudgeOnline/problem.php?id=1629 这题我想了很久都没想出来啊... 其实任意两头相邻的牛交换顺序对其它牛是没有影响的.. 那么我 ...
- BZOJ 1629 [Usaco2005 Nov]Cow Acrobats:贪心【局部证明】
题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1332 题意: 有n头牛在“叠罗汉”. 第i头牛的体重为w[i],力量为s[i]. 一头 ...
- poj3045 Cow Acrobats(二分最大化最小值)
https://vjudge.net/problem/POJ-3045 读题后提取到一点:例如对最底层的牛来说,它的崩溃风险=所有牛的重量-(底层牛的w+s),则w+s越大,越在底层. 注意范围lb= ...
随机推荐
- 构建根文件系统之init进程分析
busybox是ls.cp等命令的集合. 执行ls时,实际上是执行了busybox ls 执行cp时,实际上是执行了busybox cp 分析init程序之前,再让我们回想一下我们的目标:u-boot ...
- git stash 命令
摘自: http://blog.csdn.net/longxiaowu/article/details/26815433 关于git stash命令的使用方法网上一大把,我想记录的是我在使用过程中觉得 ...
- c# 第11节 运算符大全
本节内容: 1:数学运算符 2:赋值运算符 3:关系运算符 4:布尔运算符 5:位运算符 6:其他运算符 1:数学运算符 2:赋值运算符 3:关系运算符 4:布尔运算符 5:位运算符 & 运算 ...
- oracle_day1
本节内容: 1:oracle的服务 2:oracle 11 G 的新功能 3:数据库的三大范式 1:oracle的服务 安装完oracle 想要使用oracle 必须要启动的两个服务. 要是还想要使用 ...
- 莫烦TensorFlow_05 add_layer
import tensorflow as tf import numpy as np def add_layer(inputs, in_size, out_size, activation_funct ...
- JDOJ 2898 删数问题
洛谷 P1106 删数问题 https://www.luogu.org/problemnew/show/P1106 JDOJ 2898: 删数问题 https://neooj.com:8082/old ...
- koa中的路由
原生路由 网站一般都有多个页面.通过ctx.request.path可以获取用户请求的路径,由此实现简单的路由. const main = ctx => { if (ctx.request.pa ...
- cerely-分布式异步任务队列
Celery 是一个强大的 分布式任务队列 的 异步处理框架,它可以让任务的执行完全脱离主程序,甚至可以被分配到其他主机上运行.我们通常使用它来实现异步任务(async task)和定时任务(cron ...
- [TJOI2019]唱,跳,rap,篮球(生成函数,组合数学,NTT)
算是补了个万年大坑了吧. 根据 wwj 的题解(最准确),设一个方案 \(S\)(不一定合法)的鸡你太美组数为 \(w(S)\). 答案就是 \(\sum\limits_{S}[w(S)=0]\). ...
- [LeetCode] 913. Cat and Mouse 猫和老鼠
A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns. The grap ...