poj 1548 Dilworth定理(机器人清理垃圾)
来源:互联网 发布:c网络爬虫源码 编辑:程序博客网 时间:2024/05/23 01:12
题意:一个矩形区域,在若干个给定的坐标上有垃圾。机器人从西北角(矩形区域的左上角)开始清理,它只能向东或者向南行进,如果到达了东南角(矩形区域的右下角)则完成了它的使命。问最少用多少个机器人可以将所有的垃圾清理完毕。
思路:Dilworth定理应用。把坐标看成一对数组,也就是求这个数组的最长反链。实际上这样一看,与poj1065的题意如出一辙。先排序,然后求最长下降子序列。
#include <stdio.h>#include <stdlib.h>#include <string.h>#define N 28typedef struct node{ int a,b;}node;node p[N*N];int dp[N],n=0,len=0,a,b;int cmp(const void *a,const void *b){ if((*(node *)a).a == (*(node *)b).a) return (*(node *)a).b - (*(node *)b).b; return (*(node *)a).a - (*(node *)b).a;}int find (int x,int len){ int low,high,mid; low = 0; high = len; while(low <= high){ mid = (low+high)>>1; if(dp[mid] == x) return mid; else if(dp[mid] > x) low = mid+1; else high = mid-1; } return low;}int main(){ while(scanf("%d %d",&a,&b) &&a!=-1&&b!=-1){ int i,j; if(a && b){ p[n].a = a; p[n++].b = b; continue; } qsort(p,n,sizeof(node),cmp); for(i = 0;i<n;i++){ j = find(p[i].b,len); if(j == len+1) dp[++len] = p[i].b; else dp[j] = p[i].b; } printf("%d\n",len+1); n = 0; len = 0; memset(dp,0,sizeof(dp)); } return 0;}
0 0
- poj 1548 Dilworth定理(机器人清理垃圾)
- POJ 1065 贪心算法(Dilworth定理)
- POJ 1065-Dilworth定理
- poj 3636 Dilworth定理(嵌套方形娃娃) Dilworth定理详细讲解
- 偏序关系和Dilworth定理(poj 1548)
- POJ 3636 POJ 1065 (Dilworth定理)
- poj1065(dilworth定理+lis)
- Dilworth定理
- Dilworth定理
- DilWorth定理
- Dilworth定理
- 链-反链-Dilworth定理 (转载)
- 偏序集的Dilworth定理学习 (转载)
- 【POJ1548】Robots Dilworth定理(偏序集定理2)
- 【POJ1065】Wooden Sticks Dilworth定理(偏序集定理2)
- 【POJ3636】Nested Dolls Dilworth定理(偏序集定理二)
- 偏序集-Dilworth定理
- dilworth定理{偏序集}
- 在车牌识别中当前最先进的车牌定位方法有哪些?
- Unity3d 物体跟随鼠标移动
- ERROR 1005 (HY000): Can't create table '.\user\#sql-558_5.frm' (errno: 1
- windows 字体显示知识
- 共享内存的使用
- poj 1548 Dilworth定理(机器人清理垃圾)
- 单链表逆转
- Android SIP 网络通话
- 嵌入式 hi3518平台以太网网络模块设计包括重连机制和网线检测机制
- jsp动态导航栏
- 正则表达式生成器
- JFrame
- C# SendMessage 第一次接触
- WINDOWS下使用PTHREAD库