首页 技术 正文
技术 2022年11月18日
0 收藏 858 点赞 3,865 浏览 2114 个字
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;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,401
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,813
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,897