hdu 1069 Monkey and Banana
来源:互联网 发布:nginx 目录映射 编辑:程序博客网 时间:2024/05/18 02:08
题目
http://acm.hdu.edu.cn/showproblem.php?pid=1069
分析
和hdu 1025类似,区别在于本题需要能够识别出来每个矩形,相邻的三个面都要存储(这样才能找到所有合理的组合情况),所以数组中元素个数为矩形个数的3倍。
决策:
当处理第i个的时候,决策为前边i-1个,依次遍历找到最大值(即相容的个数中最大的)
复杂度
O(N*N)
涉及内容
算法:动态规划
感想
分析题目的时候,首先确定用什么方法,然后再确定怎么变化题目条件符合方法,可能会快速找到解题思路
代码
#include <iostream>#include <vector>#include <algorithm>using namespace std;typedef struct point{ point(){ v=x=y=0; } point(int a,int b,int c){ x=a;y=b;v=c; } int x,y; int v;} Point;bool SortPre(Point X,Point Y){ if(X.x>Y.x) return true; else if(X.x==Y.x && X.y>Y.y) return true; return false;}class Mokey{public: vector<Point> coll; vector<int> h; int num,height,most;//最大高度 int cx,cy,tx,ty;//当前底面积 int total; static int ci; int e[3]; void init(int n) { most=height=0; cx=cy=65535; coll.clear(); h.clear(); num=n*3; while(n--) { cin>>e[0]>>e[1]>>e[2]; sort(e,e+3); coll.push_back(Point(e[0],e[1],e[2])); coll.push_back(Point(e[0],e[2],e[1])); coll.push_back(Point(e[1],e[2],e[0])); } sort(coll.begin(),coll.end(),SortPre); } void LDA() { most=coll[0].v; for(int i=0;i<coll.size();++i) { h.push_back(coll[i].v); for(int j=0;j<i;++j) { if(coll[i].x<coll[j].x&&coll[i].y<coll[j].y&&h[i]<coll[i].v+h[j]) { h[i]=(coll[i].v+h[j]); } } most=most>h[i]?most:h[i]; } } void print() { cout<<"Case "<<ci++<<": maximum height = "<<most<<endl; } void exec(int n) { init(n); LDA(); print(); }};int Mokey::ci=1;int main(){ Mokey m; int n; while(1) { cin>>n; if(n == 0) break; m.exec(n); } return 0;}
- HDU 1069 Monkey and Banana
- hdu 1069 Monkey and banana
- hdu 1069 Monkey and Banana
- HDU 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- HDU 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- HDU 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- HDU 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- HDU 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- SSE2指令--使用SSE2的整型内存操作和初始化:设置(Set)
- 简单的数据存储--Preferences的使用
- 一键退出一个app中所有activity
- 杭电1312HDU acm ---Red and Black---DFS深度优先算法
- Android中 onInterceptTouchEvent, onTouchEvent 理解
- hdu 1069 Monkey and Banana
- 手把手教你调试STL容器(上)
- Android JNI实例代码(二)
- ARM小问题
- cocos2d-x ubuntu开发
- 在eclipse中编译Launcher2的方法
- nslookup用法
- 下载
- wp-admin文件下