日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codevs 1689 建造高塔

發布時間:2023/12/13 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 N50000,其余數字≤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; }

轉載于:https://www.cnblogs.com/nancheng58/p/6070769.html

總結

以上是生活随笔為你收集整理的Codevs 1689 建造高塔的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。