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 建造高塔的更多相关文章

  1. codevs 1689 搭建高塔

    /*机智sort二维转一维*/ #include<iostream> #include<cstdio> #include<cstring> #include< ...

  2. 建造高塔(codevs 1689)

    题目描述 Description n有n种石块,石块能无限供应.每种石块都是长方体,其中第i种石块的长.宽.高分别为li.wi.hi.石块可以旋转,使得其中两维成为长度和宽度,第三维成为高度.如果要把 ...

  3. H5坦克大战之【建造敌人的坦克】

      公司这几天在准备新版本的上线,今天才忙里偷闲来写这篇博客.接着上一篇的"H5坦克大战之[玩家控制坦克移动2]"(http://www.cnblogs.com/zhouhuan/ ...

  4. codevs 3289 花匠

    题目:codevs 3289 花匠 链接:http://codevs.cn/problem/3289/ 这道题有点像最长上升序列,但这里不是上升,是最长"波浪"子序列.用动态规划可 ...

  5. (转)使用 SCons 轻松建造程序

    在软件项目开发过程中,make 工具通常被用来建造程序.make 工具通过一个被称为 Makefile 的配置文件可以自动的检测文件之间的依赖关系,这对于建造复杂的项目非常有帮助,然而,编写 Make ...

  6. codevs 1082 线段树练习 3(区间维护)

    codevs 1082 线段树练习 3  时间限制: 3 s  空间限制: 128000 KB  题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...

  7. codevs 1285 二叉查找树STL基本用法

    C++STL库的set就是一个二叉查找树,并且支持结构体. 在写结构体式的二叉查找树时,需要在结构体里面定义操作符 < ,因为需要比较. set经常会用到迭代器,这里说明一下迭代器:可以类似的把 ...

  8. codevs 1576 最长上升子序列的线段树优化

    题目:codevs 1576 最长严格上升子序列 链接:http://codevs.cn/problem/1576/ 优化的地方是 1到i-1 中最大的 f[j]值,并且A[j]<A[i] .根 ...

  9. codevs 1080 线段树点修改

    先来介绍一下线段树. 线段树是一个把线段,或者说一个区间储存在二叉树中.如图所示的就是一棵线段树,它维护一个区间的和. 蓝色数字的是线段树的节点在数组中的位置,它表示的区间已经在图上标出,它的值就是这 ...

随机推荐

  1. HW4.39

    public class Solution { public static void main(String[] args) { double sum; double baseSalary = 500 ...

  2. 解读(GoogLeNet)Going deeper with convolutions

    (GoogLeNet)Going deeper with convolutions Inception结构 目前最直接提升DNN效果的方法是increasing their size,这里的size包 ...

  3. Codeforces245H - Queries for Number of Palindromes(区间DP)

    题目大意 给定一个字符串s,q个查询,每次查询返回s[l-r]含有的回文子串个数(题目地址) 题解 和有一次多校的题目长得好相似,这个是回文子串个数,多校的是回文子序列个数 用dp[i][j]表示,s ...

  4. 大型机汇编(mainframe assembler/HLASM)之COBOL解惑

    IDENTIFICATION DIVISION.             PROGRAM-ID. HELLO.                   ENVIRONMENT DIVISION.      ...

  5. codeforces 721C (拓扑+dp)

    题意就是某个人去游览,起点是1点,终点是n点,他总的游览时间不能超过t,第一行给你3个数字,点的个数n,边的个数m,时间t,然后底下m行数据,每行代表一条边,边的起点,终点和权值(走过去花的时间),然 ...

  6. hdu 4635 Strongly connected(Tarjan)

    做完后,看了解题报告,思路是一样的.我就直接粘过来吧 最终添加完边的图,肯定可以分成两个部X和Y,其中只有X到Y的边没有Y到X的边,那么要使得边数尽可能的多,则X部肯定是一个完全图,Y部也是,同时X部 ...

  7. python module的结构

    python有很多module,下面是module的结构图: 拿httplib做例子,httlip module有: 4个class( HTTPConnection,HTTPSConnection,H ...

  8. Minimum Size Subarray Sum -- leetcode

    题目描写叙述: Given an array of n positive integers and a positive integer s, find the minimal length of a ...

  9. IC芯片

    5.8寸显示屏/LB058WQ1(SD)01LG2 74HC04 0.3NXP10K    74HC138 0.37NXP20K    74HC245 0.52NXP30K    74HC595 明威 ...

  10. systemtap 列出所有linux 内核模块与相关函数1

    阿里云主机 [root@monitor klvl]# uname -aLinux monitor 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu Jul 31 17:20: ...