poj1548--Robots

Robots

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4037   Accepted: 1845

Description

Your company provides robots that can be used to pick up litter from fields after sporting events and concerts. Before robots are assigned to a job, an aerial photograph of the field is marked with a grid. Each location in the grid that contains garbage is marked. All robots begin in the Northwest corner and end their movement in the Southeast corner. A robot can only move in two directions, either to the East or South. Upon entering a cell that contains garbage, the robot will pick it up before proceeding. Once a robot reaches its destination at the Southeast corner it cannot be repositioned or reused. Since your expenses are directly proportional to the number of robots used for a particular job, you are interested in finding the minimum number of robots that can clean a given field. For example, consider the field map shown in Figure 1 with rows and columns numbered as shown and garbage locations marked with a ‘G‘. In this scheme, all robots will begin in location 1,1 and end in location 6, 7. 
 
Figure 1 - A Field Map
Figure 2 below shows two possible solutions, the second of which is preferable since it uses two robots rather than three. 
 
Figure 2 - Two Possible Solutions
Your task is to create a program that will determine the minimum number of robots needed to pick up all the garbage from a field.

Input

The input consists of one or more field maps followed by a line containing -1 -1 to signal the end of the input data. A field map consists of one or more lines, each containing one garbage location, followed by a line containing 0 0 to signal the end of the map. Each garbage location consists of two integers, the row and column, separated by a single space. The rows and columns are numbered as shown in Figure 1. The garbage locations will be given in row-major order. No single field map will have more than 24 rows and 24 columns. The sample input below shows an input file with two field maps. The first is the field map from Figure 1.

Output

The output will consist of a single line for each field map containing the minimum number of robots needed to clean the corresponding field.

Sample Input

1 2
1 4
2 4
2 6
4 4
4 7
6 6
0 0
1 1
2 2
4 4
0 0
-1 -1

Sample Output

2
1

Source

Mid-Central USA 2003

//主要找出关键意思;本题只要满足存在最少多少个划分使得每个划分里面的二元组都满足x1 <= x2并且y1 <= y2 即可:Dirworth定理

 1 #include <stdio.h>
 2 #include <algorithm>
 3 using namespace std ;
 4
 5 struct field
 6 {
 7     int h ;
 8     int z ;
 9 } ;
10 field num[600] ;
11
12 bool cmp(field h,field z)          /*
13 {
14     if(h.h == z.h)
15     return h.z < z.z ;
16     else
17     return h.h < z.h ;             /*
18 }
19
20
21 int main()
22 {
23     int m,n,i ;
24     while(~scanf("%d %d",&num[0].h, &num[0].z) , (num[0].h!=-1 , num[0].z!=-1))
25     {
26         for(i=1; ;i++)
27         {
28             scanf("%d %d",&num[i].h, &num[i].z) ;
29             if(!num[i].h , !num[i].z)
30             break;
31         }
32         sort(num, num+i, cmp) ;
33         int temp, j, k, total=0 ;
34         for(j=0; j<i; j++)                 /*不可先遍历,后统计!0个数,不是最优 ;
35         {
36             if(num[j].z != 0)
37             {
38                 temp = num[j].z ;
39                 total++;
40                 for(k=j+1; k<i; k++)
41                 {
42                     if(num[k].z >= temp)
43                     {
44                         temp=num[k].z ;
45                         num[k].z = 0 ;
46                     }
47                 }
48             }
49
50         }                                /*
51         printf("%d\n",total);
52     }
53     return 0 ;
54 }
时间: 2024-10-14 13:51:31

poj1548--Robots的相关文章

POJ1548 Robots【二分图最小路径覆盖】

题目链接: http://poj.org/problem?id=1548 题目大意: 在一个N*M(N <= 24,M <= 24)的图中,有很多垃圾, 清理垃圾的机器人从左上角开始清理.已 知机器人只能向右或是向下清理垃圾,在清理完一个地方的垃圾后可以继续向右或是向下去清理 其他垃圾.最终运行到(N,M)的位置终止.问:最少需要多少个机器人,能清理完所有的垃圾. 思路: 图中没有给N和M的大小,只是给出了垃圾的位置.输入用0 0表示一组数据输入结束.建一个结构 体来存储垃圾的坐标值.现在来建

poj图论解题报告索引

最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman-ford,spfa) poj1511 - Invitation Cards(单源来回最短路径,spfa邻接表) poj1797 - Heavy Transportation(最大边,最短路变形,dijkstra,spfa,bellman-ford) poj2240 - Arbitrage(汇率问题,

【POJ1548】Robots Dilworth定理(偏序集定理2)

题意: 有一些位置有垃圾,让机器人从左上角开始走,只能往右或者往下,问最少走多少次可以清理完所有垃圾. 题解: 一看就是网络流经典题,或者说是二分图-最小路径覆盖:但是现在毕竟是在做一些贪心,这道题用的是一种贪心相关定理,Dilworth定理. 这道题可以理解为部分两点之间有偏序(可走的关系),呃,可以视为当xa<=xb&&ya<=yb时有偏序,那么姑且认为反之则为反偏序,那么定义一条链为由n-1个偏序连接起来的n个点,那么答案就是"最长反链的大小. 比如题中的数据1

Python 爬虫-Robots协议

2017-07-25 21:08:16 一.网络爬虫的规模 二.网络爬虫的限制 ? 来源审查:判断User‐Agent进行限制 检查来访HTTP协议头的User‐Agent域,只响应浏览器或友好爬虫的访问? 发布公告:Robots协议 告知所有爬虫网站的爬取策略,要求爬虫遵守 三.Robots 协议 作用:网站告知网络爬虫哪些页面可以抓取,哪些不行形式:在网站根目录下的robots.txt文件 如果网站不提供Robots协议则表示该网站允许任意爬虫爬取任意次数. 类人类行为原则上可以不遵守Rob

robots.txt的介绍和写作

目前很多网站管理者似乎对robots.txt并没有引起多大重视,甚至不知道这么一个文件的作用.本来应该保密的信息被爬虫抓取了,公布在公网上,本应该发布到公网的信息却迟迟不被搜索引擎收录.所以下面这篇文章,就来介绍robots.txt的作用和写作 robots.txt基本介绍 robots 是一个纯文本文件,是用来告诉搜索引擎:当前这个网站上哪些部分可以被访问.哪些不可以,robots文件是存放在网站根目录下的一个纯文本文件.当搜索引擎访问一个网站时,它首先会检查该网站根目录下是否存在robots

Place the Robots 需要较强的建图能力

Place the Robots 思路:在任意一个点格子放机器人,那么它所在的行和列被控制了.我们对每一行或每一列连续的空地(草地忽视)称之为块,给每一行和每一列的块标号, 每一行的快与每一列的快相交的话,才有只有一个交点.  我们把交点当边,把行块和列块连接起来.每一个空第都是一条边.详细细节见代码. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath&

django1.5添加robots.txt

方法一:(The best way) urlpatterns = patterns( (r’^robots\.txt$’, TemplateView.as_view(template_name=’robots.txt’, content_type=’text/plain’)), ) 其他: http://stackoverflow.com/questions/6867468/setting-up-mimetype-when-using-templateview-in-django

seo课程之robots.txt的格式

其实很多人刚刚开始从事seo的时候,根本就不知道什么是robots.txt,就算知道了也不懂得robots.txt的文件格式是什么,今天小编我就来和大家分享一下吧(本文来自于e良师益友网). "robots.txt"文件包含一条或更多的记录,这些记录通过空行分开(以CR,CR/NL, or NL作为结束符),每一条记录的格式如下所示: "<field>:<optional space><value><optionalspace>

UVA10599 - Robots(II)(变形的LIS)

题意:一个机器人在n * m的网格里面捡垃圾,机器人只能向右或向下走,求出能捡到的垃圾数量的最大值,有多少条路径可以达到最大值,以及输出其中一条路径. 思路:按照题意可以看出,因为机器人只能向右和向下走,所以纵坐标就不重要的,而横坐标是递增的.当将所有拥有垃圾的格子经过计算得到它的一维值(唯一的),得到一组的数组.那就可以转化为求最长上升子序列.但这个LIS的条件是mod(m)要大于前一个.计算数量时,当d[i] = d[j] + 1时,就相当于以i为结束时的最长上升子序列比以j结束时的最长上升

实例分析Robots.txt写法

题意:经典八数码问题 思路:HASH+BFS #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 500000; const int size = 1000003; typedef int State[9]; char str[30]; int state[9],goal[9]={