1005
来源:互联网 发布:电脑桌面壁纸 知乎 编辑:程序博客网 时间:2024/05/16 00:35
题意:给定一块砖的长宽高,让你叠金字塔,下面砖的表面积必须大于上面的,求能叠到的最高高度。
思路:先将给定的所有的砖分成三种,这样的话,一块砖就有三种形态,然后将所有的排序,然后挑选,最后将所选的高加到一起即可。
感想:题干略坑
#include<iostream>
#include<cstdio>#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<iomanip>
#define INF 99999999
using namespace std;
const int MAX=100;
int height[MAX];
typedef struct node{
int w;
int l;
int h;
bool operator<(node b)const{
if(w == b.w)return l>b.l;
return w>b.w;
}
};
node s[MAX];
int main(){
int n,a,b,c,num=1;
while(cin>>n,n){
int k=0;
for(int i=0;i<n;++i){
cin>>a>>b>>c;
//对a,b,c排序.
if(a>b)a=a+b,b=a-b,a=a-b;
if(a>c)a=a+c,c=a-c,a=a-c;
if(b>c)b=b+c,c=b-c,b=b-c;
s[k].w=a,s[k].l=b,s[k++].h=c;//以a,b为底,c为高.
s[k].w=a,s[k].l=c,s[k++].h=b;//以a,c为底,b为高.
s[k].w=b,s[k].l=c,s[k++].h=a;//以b.c为底,a为高.
}
sort(s,s+k);
int Max=s[0].h;
height[0]=s[0].h;
for(int i=1;i<k;++i){
height[i]=s[i].h;
for(int j=0;j<i;++j){
if(s[i].w<s[j].w && s[i].l<s[j].l){
height[i]=max(height[i],s[i].h+height[j]);
}
}
Max=max(Max,height[i]);
}
cout<<"Case "<<num++<<": maximum height = "<<Max<<endl;
}
return 0;
}
0 0
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- 1005
- L - Demacia of the Ancients——ZOJ
- ORACLE用SYS登录报ORA-28009:connection as SYS should be as SYSDBA OR SYSOPER解决方法
- Spring DI[依赖注入]
- java基础学习(4)
- 剑指offer之面试题4替换空格
- 1005
- 聊聊Condition
- oracle赋权
- SQL中数据库的基本操作
- 第11周阅读程序(5-4)
- python正则表达式
- [bzoj4552][TJOI&HEOI2016]排序
- 8+2时间制
- mysql删除数据不能带表名