Codeforces777E. Hanoi Factory 2017-05-04 18:10 42人阅读 评论(0) 收藏
1 second
256 megabytes
standard input
standard output
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high
tower as possible. They were not ready to serve such a strange order so they had to create this new tower using already produced rings.
There are n rings in factory's stock. The i-th
ring has inner radius ai,
outer radius bi and
height hi.
The goal is to select some subset of rings and arrange them such that the following conditions are satisfied:
- Outer radiuses form a non-increasing sequence, i.e. one can put the j-th ring on the i-th
ring only if bj ≤ bi. - Rings should not fall one into the the other. That means one can place ring j on the ring i only
if bj > ai. - The total height of all rings used should be maximum possible.
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) —
the number of rings in factory's stock.
The i-th of the next n lines
contains three integers ai, bi and hi (1 ≤ ai, bi, hi ≤ 109, bi > ai) —
inner radius, outer radius and the height of the i-th ring respectively.
Print one integer — the maximum height of the tower that can be obtained.
3
1 5 1
2 6 2
3 7 3
6
4
1 2 1
1 3 3
4 6 2
5 7 1
4
In the first sample, the optimal solution is to take all the rings and put them on each other in order 3, 2, 1.
In the second sample, one can put the ring 3 on the ring 4 and
get the tower of height 3, or put the ring 1 on
the ring 2 and get the tower of height 4.
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
#define LL long long struct node
{
LL r,R,h;
} p[100005]; bool cmp(node a,node b)
{
if(a.R!=b.R)
return a.R>b.R;
return a.r>b.r;
} stack<node>s; int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1; i<=n; i++)
scanf("%lld%lld%lld",&p[i].r,&p[i].R,&p[i].h);
sort(p+1,p+n+1,cmp); while(!s.empty())
s.pop(); LL ans=0;
LL mx=-1;
for(int i=1; i<=n; i++)
{
int flag=0; while(!s.empty())
{
if(s.top().r>=p[i].R)
{
ans-=s.top().h;
s.pop();
}
else
{
ans+=p[i].h;
s.push(p[i]);
flag=1;
mx=max(mx,ans);
break;
}
}
if(flag==0)
{
ans+=p[i].h;
s.push(p[i]);
mx=max(mx,ans);
}
}
printf("%lld\n",mx);
}
return 0;
}
Codeforces777E. Hanoi Factory 2017-05-04 18:10 42人阅读 评论(0) 收藏的更多相关文章
- const char*, char const* and char *const 分类: C/C++ OpenCV 2014-11-08 18:10 114人阅读 评论(0) 收藏
const char*, char const*, char*const的区别问题几乎是C++面试中每次都会有的题目. 事实上这个概念谁都有只是三种声明方式非常相似很容易记混. Bjarne在他的 ...
- HDU2976 Dropping tests 2017-05-11 18:10 39人阅读 评论(0) 收藏
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12187 Accepted: 4257 D ...
- 团体程序设计天梯赛L2-003 月饼 2017-03-22 18:17 42人阅读 评论(0) 收藏
L2-003. 月饼 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不 ...
- c++map的用法 分类: POJ 2015-06-19 18:36 11人阅读 评论(0) 收藏
c++map的用法 分类: 资料 2012-11-14 21:26 10573人阅读 评论(0) 收藏 举报 最全的c++map的用法 此文是复制来的0.0 1. map最基本的构造函数: map&l ...
- Rebuild my Ubuntu 分类: ubuntu shell 2014-11-08 18:23 193人阅读 评论(0) 收藏
全盘格式化,重装了Ubuntu和Windows,记录一下重新配置Ubuntu过程. //build-essential sudo apt-get install build-essential sud ...
- HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏
Automatic Judge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- Doubles 分类: POJ 2015-06-12 18:24 11人阅读 评论(0) 收藏
Doubles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19954 Accepted: 11536 Descrip ...
- 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏
制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...
- highgui.h备查 分类: C/C++ OpenCV 2014-11-08 18:11 292人阅读 评论(0) 收藏
/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...
随机推荐
- HttpSession的关键属性和方法
1.当一个用户向服务器发送第一个请求时,服务器为其建立一个session,并为此session创建一个标识号:2.这个用户随后的所有请求都应包括这个标识号.服务器会校对这个标识号以判断请求属于哪个se ...
- ssh 免密码登录,以及 本地和远端用户名不一致 问题
ssh 远程登录 ssh -l u1 u1@192.168.0.7 ssh u1@192.168.0.7 每次远程都要输入 用户名,密码 比较麻烦.所以比较好的是免密码登录 1.安装ssh服务器 su ...
- struts2 资源国际化
web.xml: <?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp ...
- GBDT 将子树结果当成lr输出
http://scikit-learn.org/stable/auto_examples/ensemble/plot_feature_transformation.html#example-ensem ...
- 第八章 高级搜索树 (xa2)红黑树:结构
- PyQt5信号与槽
简单使用 可以使用designer的一个模式定义,也可以自己定义,在__init__函数里,self.btn.clicked.connect(self.text.clear). 注意:槽不用加括号,可 ...
- python的select服务端的代码和客户端的代码
服务端的代码 import socket import queue import select ip_bind = ("127.0.0.1",9000) message_queue ...
- sqlserver 几种datatime的区别
参考文章1 smalldatetime 占4位精确到分钟.时间从1900.1.1到2079.6.6datetime占8位精确到毫秒.时间从1753.1.1到9999.12.31 参考文章2 datet ...
- win10下docker安装和配置镜像仓库
初学docker记录一下流程 1.首先安装直接官网下载 DockerToolbox 即可,安装过程傻瓜式下一步即可.(这个集成了虚拟机,果然安装过的可以去掉) 2.安装好后双击Docker Quick ...
- actionView
类似于actionBar也是在导航栏里用但是他使用的是menu菜单设置菜单项的AsAction=“always|withText” 本例使用LoaderCallbacks<Cursor>接 ...