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 ...
随机推荐
- 迷你MVVM框架 avalonjs 学习教程18、一步步做一个todoMVC
大凡出名的MVC,MVVM框架都有todo例子,我们也搞一下看看avalon是否这么便宜. 我们先从react的todo例子中扒一下HTML与CSS用用. <!doctype html> ...
- js中常见的创建对象的方法
前两天好好的把高程对象那一块又读了下,顺便写点笔记.补一句:代码都测试过了,应该没有问题的.可以直接拿到控制台跑! 1.工厂模式 function person(name, age, job) { v ...
- Centos7 vnc
这是一个关于怎样在你的 CentOS 7 上安装配置 VNC 服务的教程.当然这个教程也适合 RHEL 7 .在这个教程里,我们将学习什么是 VNC 以及怎样在 CentOS 7 上安装配置 VNC ...
- 可以foreach的 必须继承IEnumable 接口才行
只要是继承IEnumable 都可以用foreach遍历
- datagrid数据表格的维护
想想刚开始学jsp, 用application做一个简单的数据库, 简单的注册页面, 跟这个相比就是过家家 <%@ page language="java" contentT ...
- 神龟快跑,2016做的一款UWP游戏
神龟快跑,2016做的一款UWP游戏, 实际是H5页面, 用LAYA转AS3得到的 安装地址 https://www.microsoft.com/zh-cn/store/p/神龟快跑/9nblggh4 ...
- 在UNITY中按钮的高亮用POINT灯实现,效果别具一番风味
在UNITY中按钮的高亮用POINT灯实现,效果别具一番风味
- ECMAScript5新特性之isFrozen、freeze
对象被冻结后: 1 不能添加属性. 2 不能删除属性. 3 不能修改属性.(赋值) 4 不能修改属性描述符.(会抛异常) var fruit = { name : '苹果', desc : '红富士' ...
- Asp.net实现同页面内多图片自动上传并带预览显示
FileUpload控件实现单按钮图片自动上传并带预览显示 1.实现原理: 此方法适合针对有后台生成的图片相关内容,例如购物网站商品展示页面中的封面图片,图片的数量由后台访问数据库,并加载到页面.这种 ...
- 在CentOS7上部署Kubernetes集群
在CentOS7上部署Kubernetes集群 文/FCBusquest 2015-12-22 18:36:00 简介 Kubernetes(k8s)是Google开源的大规模容器集群管理系统, 本文 ...