Codeforces 777E:Hanoi Factory(贪心+栈)
http://codeforces.com/problemset/problem/777/E
题意:给出n个环状圆柱,每个圆环有一个内半径a,外半径b,和高度h,只有外半径bj <= bi并且bj > ai,这样j才可以放在i的上面,问最大能达到的高度是多少。
思路:一开始用数组dp错了,主要是推错转移方程。用不到之前的信息了。如果要利用之前的信息,其实是可以用栈来维护的。先按照外半径从大到小,外半径相同内半径从大到小排序,这样能保证如果前面符合,后面放上去能使高度最大。
#include <bits/stdc++.h>
using namespace std;
#define N 100010
typedef long long LL;
struct node {
LL a, b, h;
} p[N];
stack<node> sta; bool cmp(const node &a, const node &b) {
if(a.b == b.b) return a.a < b.a;
return a.b > b.b;
} int main() {
int n;
scanf("%d", &n);
for(int i = ; i <= n; i++) scanf("%lld%lld%lld", &p[i].a, &p[i].b, &p[i].h);
sort(p + , p + + n, cmp);
LL ans = p[].h, cnt = p[].h;
sta.push(p[]);
for(int i = ; i <= n; i++) {
if(sta.empty()) {
cnt += p[i].h; sta.push(p[i]);
continue;
}
node top = sta.top();
if(top.a < p[i].b) {
cnt += p[i].h;
sta.push(p[i]);
} else {
ans = max(ans, cnt);
while(top.a >= p[i].b) {
cnt -= top.h;
sta.pop();
if(sta.empty()) break;
top = sta.top();
}
sta.push(p[i]);
cnt += p[i].h;
}
ans = max(ans, cnt);
}
printf("%lld\n", ans);
return ;
}
Codeforces 777E:Hanoi Factory(贪心+栈)的更多相关文章
- Codeforces 777E - Hanoi Factory(贪心+栈)
题目链接:http://codeforces.com/problemset/problem/777/E 题意:有n个环给你内环半径.外环半径和高度,叠这些环还要满足以下要求: ①:下面的环的外径要&g ...
- Codeforces 777E Hanoi Factory(线段树维护DP)
题目链接 Hanoi Factory 很容易想到这是一个DAG模型,那么状态转移方程就出来了. 但是排序的时候有个小细节:b相同时看a的值. 因为按照惯例,堆塔的时候肯定是内半径大的在下面. 因为N有 ...
- codeforces-777E Hanoi Factory (栈+贪心)
题目传送门 题目大意: 现在一共有N个零件,如果存在:bi>=bj&&bj>ai的两个零件i,j,那么此时我们就可以将零件j放在零件i上.我们现在要组成一个大零件,使得高度 ...
- Codeforces 777E:Hanoi Factory(贪心)
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a specia ...
- Codeforces777E. Hanoi Factory 2017-05-04 18:10 42人阅读 评论(0) 收藏
E. Hanoi Factory time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- codeforces 704B - Ant Man 贪心
codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...
- CodeForces - 50A Domino piling (贪心+递归)
CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...
- Codeforces 777E(离散化+dp+树状数组或线段树维护最大值)
E. Hanoi Factory time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- CF #401 (Div. 2) E. Hanoi Factory (栈+贪心)
题意:给你一堆汉诺塔的盘子,设内半径为a,设外半径为b,高度为h,如果bj ≤ bi 同时bj > ai 我们就认为i盘子能落在在j盘子上,问你最高能落多高 思路:一看题意我们就能想到贪心,首先 ...
随机推荐
- blockchain_eth客户端安装 & geth使用 &批量转账(二)
回顾一下,前面我们讲到启动geth geth --rpc --datadir "F:/geth/Geth/" --light console 2>console.log 这一 ...
- WPF Path和图形
<Window x:Class="GeometryDemo.MainWindow" xmlns="http://schemas.microsoft.com/winf ...
- 【C++】int转string,double转string方法,string转int,string转double方法
C++的格式比较多比较复杂,转换起来有很多方法,我这里只提供一种,仅供参考. int或double转string 使用字符串流的方式可以比较简单的完成转换 需要添加头文件 #include <s ...
- x:Static
用途:访问代码中的变量等 后台定义一个变量 public partial class GetStaticFromBackgroundCode : Window { public static stri ...
- EF学习目录
EF EF性能优化 EF延迟加载LazyLoading EF相关报错 EF 事务 Entity相互关系 Entity种类(动态代理) DbContext Entity States Code Firs ...
- Bootstrap 标签徽章巨幕页头
@{ Layout = null;}<!DOCTYPE html><html><head> <meta name="viewport&q ...
- telerik ChartGrid浅谈
在最近接触的项目中,有很多都是以Chart图表的方式呈现出来的,关于telerik Chart的使用,有几个小点跟大家分享一下. 1:本例子使用的Chart的命名空间为 xmlns:telerik=h ...
- 绕过010Editor网络验证(用python做一个仿真http server真容易,就几行代码)
010Editor是一款非常强大的十六进制编辑器,尤其是它的模板功能在分析文件格式时相当好用!网上现在也有不少010Editor的破解版,如果没钱或者舍不得花钱买授权的话,去官方下载安装包再使用注册机 ...
- Ionic2开发环境搭建-VS 2017
原文:Ionic2开发环境搭建-VS 2017 目前在VS 2017中创建Ionic2版本项目 注:在VS中开发Ionic项目,使用的Ionic(v2.x),Cordova(v6.3.1),Angul ...
- Application.StartupPath和System.Environment.CurrentDirectory的区别
System.Environment.CurrentDirectory的含义是获取或设置当前工作路径,而Application.StartupPath是获取程序启动路径,表面上看二者没什么区别,但实际 ...