Problem3-1005
来源:互联网 发布:网站域名续费多少钱 编辑:程序博客网 时间:2024/05/22 15:02
简单题意:给定一块砖的 长宽高,让你叠金字塔,下面砖的表面积必须大于上面的,求能叠到的最高高度。
解题思路:先将给定的所有的砖分成三种,这样的话,一块砖就有三种形态,然后将所有的排序,然后挑选,最后将所选的高加到一起即可。
代码如下:
#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);//排序,以底边中最小的边来排序,这样使得第i个箱子只能放在第i个箱子的前面的箱子上,当然也可以按照底边面积排序.
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;
}
- Problem3-1005
- Problem3
- Problem3
- snort problem3
- Problem3-1001
- Problem3-1002
- Problem3-1006
- Problem3-1004
- Problem3-1015
- Problem3-1014
- Problem3-1024
- Problem3-1003
- Problem3-1017
- Problem3-1011
- Problem3-1010
- Problem3-1022
- Problem3-1016
- Problem3-1008
- 选择法排序
- 浅谈iOS开发mvvm模式
- phantomjs使用说明
- 【AD/DA】的一些基础知识
- SQLite的使用
- Problem3-1005
- 安装redis live监控工具
- 如果有navigation bar, 在navigation bar 添加一个view来设置颜色
- asm.jar 安卓手机屏幕在电脑上显示
- 自定义ToggleButton背景图片拉伸的现象
- nyoj 239 月老的难题 (最大二分图匹配匈牙利算法)
- 应用数学(转载)
- Java系统中,使用log4j2,再引入Kafka依赖后,出现log dependency警告的解决
- LeetCode 342. Power of Four