HDU 1069 Monkey and Banana
来源:互联网 发布:印度 种姓 知乎 编辑:程序博客网 时间:2024/05/18 00:23
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069
解析:就是一种叠罗汉问题,可以用dp,不过这题目数据范围较小,所以可以用floyd最长路算法水过,,
//算法:箱子全部看成点,当a箱子上能放b箱子时,a->b之间连个有向边。那么问题就变成求图中最大的有向边,即floyd来求最长路(dijkstra只能求最短路)#include<stdio.h>#include<string.h>#define Max(x,y) x<y?y:x#define INF 1000000struct point{int x,y,h;}p[110];int n,map[110][110];int main(){int count = 1;while(scanf("%d",&n) != EOF && n != 0){memset(p,0,sizeof(p));memset(map,0,sizeof(map));int a,b,c,cnt = 1;for(int i = 1 ; i <= n; i ++){scanf("%d%d%d",&a,&b,&c);//每个箱子都有三种情况,衍生出三个点p[cnt].x = a;p[cnt].y = b;p[cnt++].h = c;p[cnt].x = b;p[cnt].y = c;p[cnt++].h = a;p[cnt].x = c;p[cnt].y = a;p[cnt++].h = b;}p[0].x = p[0].y = INF;//给定把所有的箱子都看成在地面上,0节点代表地面p[0].h = 0;for(int i = 0 ; i < cnt; i ++)for(int j = 0 ; j < cnt ; j ++){if((p[i].x > p[j].x && p[i].y > p[j].y)||(p[i].x > p[j].y && p[i].y > p[j].x))//如果有边,边权就是上面的箱子的高度map[i][j] = p[j].h ;elsemap[i][j] = -INF;}int cnt2 = 0;for(int k = 0 ; k < cnt ; k++)//floyd算法,注意k是在最外层的循环,不能换循环{for(int i = 0 ; i < cnt ; i ++){for(int j = 0 ;j < cnt ; j ++)if(map[i][j] < map[i][k] + map[k][j])map[i][j] = map[i][k] + map[k][j];}}int max = -INF;for(int i = 0 ; i < cnt; i ++)max = Max(max,map[0][i]);printf("Case %d: maximum height = %d\n",count++,max);}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
- error C2264函数定义或声明中有错误;未调用函数
- Chrome错误 312 (net::ERR_UNSAFE_PORT):未知错误
- java动态代理原理(Proxy,InvocationHandler),含$Proxy0源码
- Linux一些重要的头文件
- HDU 1520 Anniversary party
- HDU 1069 Monkey and Banana
- U-Boot启动过程完全分析
- 我的架构经验小结(一)-- 常用的架构模型
- vim替换命令
- 简介一些黑盒测试的方法
- php 数组处理函数 2013.07.5
- linux内核设计与实现(第九章)----内核同步介绍
- windows7 利用虚拟wifi功能建立AP
- 解决mysql命令行和sqlyog乱码的问题