Codevs 1689 建造高塔
1689 建造高塔
时间限制: 1 s
空间限制: 128000 KB
题目等级 : **钻石 Diamond**
题目描述 Description
n有n种石块,石块能无限供应。每种石块都是长方体,其中第i种石块的长、宽、高分别为li、wi、hi。石块可以旋转,使得其中两维成为长度和宽度,第三维成为高度。如果要把一个石块放在另一个石块上面,必须保证上面石块的长和宽都分别严格小于下面石块的长和宽。这意味着,即使两块长宽相同的石块也不能堆砌起来。
现在神犇想知道,最多能用上多少块石头呢?
输入描述 Input Description
第一行,N;
以下N行,每行三个数,表示第i种石头的长宽高。
输出描述 Output Description
一个整数,表示最多能用上多少块石头。
样例输入 Sample Input
3
1 1 1
2 2 2
3 3 4
样例输出 Sample Output
3
数据范围及提示 Data Size & Hint
N≤50000,其余数字≤maxlongint。
分类标签 Tags
**动态规划**
/*
n^2 60.
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#define MAXN 50001
using namespace std;
int n,tot,ans;
struct data{
int x,y,tot;
}s[MAXN*6];
int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
return x*f;
}
bool cmp(const data & x,const data & y)
{
if(x.x!=y.x) return x.x<y.x;
return x.y<y.y;
}
int main()
{
int x,y,z;
n=read();
for(int i=1;i<=n;i++)
{
x=read();y=read();z=read();
s[++tot].x=x;s[tot].y=y;s[++tot].x=y;s[tot].y=x;
s[++tot].x=y;s[tot].y=z;s[++tot].x=x;s[tot].y=z;
s[++tot].x=z;s[tot].y=x;s[++tot].x=z;s[tot].y=y;
}
sort(s+1,s+tot+1,cmp);
for(int i=1;i<=tot;i++)
{
s[i].tot=1;
for(int j=i-1;j>=1;j--)
{
if(s[i].y>s[j].y&&s[i].x>s[j].x)
s[i].tot=max(s[i].tot,s[j].tot+1);
}
}
for(int i=1;i<=tot;i++)
ans=max(ans,s[i].tot);
printf("%d",ans);
return 0;
}
/*
nlogn.
左端点排序.
右端点从大到小排序.
防止左端点相等的点被更新.
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#define MAXN 50001
using namespace std;
int n,tot,ans,l=1,c[MAXN*6];
struct data{
int x,y,tot;
}s[MAXN*6];
int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
return x*f;
}
int erfen(int x){
int ll=0,r=l,mid;
while(ll<r){
mid=(r+ll)>>1;
if(x>c[mid]) ll=mid+1;
else r=mid;
}
return ll;
}
bool cmp(const data & x,const data & y)
{
if(x.x!=y.x) return x.x<y.x;
return x.y>y.y;
}
int main()
{
int x,y,z;
n=read();
for(int i=1;i<=n;i++)
{
x=read();y=read();z=read();
s[++tot].x=x;s[tot].y=y;s[++tot].x=y;s[tot].y=x;
s[++tot].x=y;s[tot].y=z;s[++tot].x=x;s[tot].y=z;
s[++tot].x=z;s[tot].y=x;s[++tot].x=z;s[tot].y=y;
}
sort(s+1,s+tot+1,cmp);
c[1]=s[1].y;
for(int i=2;i<=tot;i++)
{
s[i].tot=1;
if(s[i].y>c[l]) c[++l]=s[i].y;
else {
int p=erfen(s[i].y);c[p]=s[i].y;
}
}
printf("%d",l);
return 0;
}
Codevs 1689 建造高塔的更多相关文章
- codevs 1689 搭建高塔
/*机智sort二维转一维*/ #include<iostream> #include<cstdio> #include<cstring> #include< ...
- 建造高塔(codevs 1689)
题目描述 Description n有n种石块,石块能无限供应.每种石块都是长方体,其中第i种石块的长.宽.高分别为li.wi.hi.石块可以旋转,使得其中两维成为长度和宽度,第三维成为高度.如果要把 ...
- H5坦克大战之【建造敌人的坦克】
公司这几天在准备新版本的上线,今天才忙里偷闲来写这篇博客.接着上一篇的"H5坦克大战之[玩家控制坦克移动2]"(http://www.cnblogs.com/zhouhuan/ ...
- codevs 3289 花匠
题目:codevs 3289 花匠 链接:http://codevs.cn/problem/3289/ 这道题有点像最长上升序列,但这里不是上升,是最长"波浪"子序列.用动态规划可 ...
- (转)使用 SCons 轻松建造程序
在软件项目开发过程中,make 工具通常被用来建造程序.make 工具通过一个被称为 Makefile 的配置文件可以自动的检测文件之间的依赖关系,这对于建造复杂的项目非常有帮助,然而,编写 Make ...
- codevs 1082 线段树练习 3(区间维护)
codevs 1082 线段树练习 3 时间限制: 3 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...
- codevs 1285 二叉查找树STL基本用法
C++STL库的set就是一个二叉查找树,并且支持结构体. 在写结构体式的二叉查找树时,需要在结构体里面定义操作符 < ,因为需要比较. set经常会用到迭代器,这里说明一下迭代器:可以类似的把 ...
- codevs 1576 最长上升子序列的线段树优化
题目:codevs 1576 最长严格上升子序列 链接:http://codevs.cn/problem/1576/ 优化的地方是 1到i-1 中最大的 f[j]值,并且A[j]<A[i] .根 ...
- codevs 1080 线段树点修改
先来介绍一下线段树. 线段树是一个把线段,或者说一个区间储存在二叉树中.如图所示的就是一棵线段树,它维护一个区间的和. 蓝色数字的是线段树的节点在数组中的位置,它表示的区间已经在图上标出,它的值就是这 ...
随机推荐
- Linux下安装mysql5.6.11(找点有用的信息太费劲)(转)
Linux下安装mysql5.6.11(找点有用的信息太费劲) (2013-04-25 10:25:09) 1.申请阿里云Linux服务器 昨天在阿里云申请了一个免费试用5天的Linux云服务 ...
- Storm系列(四)Topology提交校验过程
功能:提交一个新的Topology,并为Topology创建storm-id(topology-id),校验其结构,设置必要的元数据,最后为Topology分配任务. 实现源码: 1 ); Conf ...
- HW4.45
public class Solution { public static void main(String[] args) { int count = 0; for(int i = 1; i < ...
- HW2.13
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- POJ-3468 A Simple Problem with Integers Splay Tree区间练习
题目链接:http://poj.org/problem?id=3468 以前用线段树做过,现在用Splay Tree A了,向HH.kuangbin.cxlove大牛学习了各种Splay各种操作,,, ...
- HDU-4115 Eliminate the Conflict 2sat
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4115 题意:Alice和Bob玩猜拳游戏,Alice知道Bob每次会出什么,为了游戏公平,Bob对Al ...
- eclipse中的maven配置
1.下载最新版eclipse,包含maven版本 2.配置maven本地仓库(修改settings.xml)
- PL/SQL基础
打印 hi set serveroutput on --打开输出开关 declare --说明部分(变量说明,光标申明或者例外说明) begin --程序 ...
- java-1-java开发环境安装及配置-绝对权威
1,下载安装jdk1.8u45 http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html 一般安装目录 ...
- 要注意null合并运算符的优先级比+还要低
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:要注意null合并运算符的优先级比+还要低.