您的位置:首页 > 其它

HDOJ 1069 Monkey and Banana

2015-05-11 10:01 239 查看
题意:在高度为h处有一串香蕉,猴子想要拿到它,但是他的高度不够,需要通过长方体木块的堆积才能拿到,已知有n钟长宽高分别为x,y,z的长方体木块,每种木块的个数足够多,判断这些木块可以堆叠的最大高度

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069

思路:动态规划。对每个长方形进行六种旋转,在对底上的中一条边进行排序,求出最大可能。

注意点:旋转方向六种,分别为(x,y,z),(x,z,y),(y,x,z),(y,z,x),(z,x,y),(z,y,x)

以下为AC代码:

Run IDSubmit TimeJudge StatusPro.IDExe.TimeExe.MemoryCode Len.LanguageAuthor
116225902014-09-09 00:53:51Accepted106915MS412K2080 BG++luminous11
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
//#include <unordered_map>
//#include <unordered_set>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define RDI(a) scanf ( "%d", &a )
#define RDII(a, b) scanf ( "%d%d", &a, &b )
#define RDIII(a, b, c) scanf ( "%d%d%d", &a, &b, &c )
#define RS(s) scanf ( "%s", s )
#define PI(a) printf ( "%d", a )
#define PIL(a) printf ( "%d\n", a )
#define PII(a,b) printf ( "%d %d", a, b )
#define PIIL(a,b) printf ( "%d %d\n", a, b )
#define PIII(a,b,c) printf ( "%d %d %d", a, b, c )
#define PIIIL(a,b,c) printf ( "%d %d %d\n", a, b, c )
#define PL() printf ( "\n" )
#define PSL(s) printf ( "%s\n", s )
#define rep(i,m,n) for ( int i = m; i <  n; i ++ )
#define REP(i,m,n) for ( int i = m; i <= n; i ++ )
#define dep(i,m,n) for ( int i = m; i >  n; i -- )
#define DEP(i,m,n) for ( int i = m; i >= n; i -- )
#define repi(i,m,n,k) for ( int i = m; i <  n; i += k )
#define REPI(i,m,n,k) for ( int i = m; i <= n; i += k )
#define depi(i,m,n,k) for ( int i = m; i >  n; i += k )
#define DEPI(i,m,n,k) for ( int i = m; i >= n; i -= k )
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
using namespace std;
const double pi = acos(-1);
template <class T>
inline bool RD ( T &ret )
{
char c;
int sgn;
if ( c = getchar(), c ==EOF )return 0; //EOF
while ( c != '-' && ( c < '0' || c > '9' ) ) c = getchar();
sgn = ( c == '-' ) ? -1 : 1;
ret = ( c == '-' ) ? 0 : ( c - '0' );
while ( c = getchar() , c >= '0' && c <= '9' ) ret = ret * 10 + ( c - '0' );
ret *= sgn;
return 1;
}
inline void PD ( int x )
{
if ( x > 9 ) PD ( x / 10 );
putchar ( x % 10 + '0' );
}
const double eps = 1e-10;
const int dir[4][2] = { 1,0, -1,0, 0,1, 0,-1 };
struct node{
int x, y, z, s, cnt;
node(){}
node( int _cnt ) : cnt(_cnt) {}
node( int _x, int _y, int _z ) : x(_x), y(_y), z(_z), cnt(_z), s(_x*_y) {}
node( int _x, int _y, int _z, int _cnt ) : x(_x), y(_y), z(_z), cnt(_cnt) {}
friend bool operator < ( const node &a, const node &b ){
if ( a.x != b.x )
return a.x > b.x;
else
return a.y > b.y;
}
};
vector<node> k;
int main()
{
int n;
int ncase = 1;
while ( RDI ( n ) != EOF && n ){
k.clear();
int x, y, z;
rep ( i, 0, n ){
cin >> x >> y >> z;
k.push_back( node ( x, y, z ) );
k.push_back( node ( y, x, z ) );
k.push_back( node ( y, z, x ) );
k.push_back( node ( z, y, x ) );
k.push_back( node ( x, z, y ) );
k.push_back( node ( z, x, y ) );
}
sort ( all ( k ) );
int ans = 0;
rep ( i, 0, k.size() ){
rep ( j, 0, i ){
if ( k[i].x < k[j].x && k[i].y < k[j].y ){
k[i].cnt = max ( k[i].cnt, k[j].cnt + k[i].z );
ans = max ( ans, k[i].cnt );
}
}
}
printf ( "Case %d: maximum height = %d\n", ncase ++, ans );
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: