ZOJ-1756 Robots
来源:互联网 发布:禅城数据便民服务中心 编辑:程序博客网 时间:2024/04/30 03:11
Robots
Time Limit: 2 Seconds Memory Limit: 65536 KB
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 SolutionsYour 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
An input file 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
#include <stdio.h>struct node {int r;int c;int f;};int main(){struct node path[600], temp;int r, c, step, i, j, n, total;n = 0;while(scanf("%d%d" , &r, &c)) {if(r == -1 && c == -1) {break;}else if(r == 0 && c == 0) {for(i = 0; i < n-1; i++) {for(j = 0; j < n-i-1; j++) {if(path[j].r > path[j+1].r || (path[j].r == path[j+1].r && path[j].c > path[j+1].c)) {temp = path[j];path[j] = path[j+1];path[j+1] = temp;}}}step = 0;total = 0;while(total < n) {i = 0;while(i < n && path[i].f) {i++;}temp = path[i];path[i].f= 1;total += 1;step++;for(i = i+1; i < n; i++) {if(!path[i].f) {if(temp.r == path[i].r) {path[i].f = 1;temp = path[i];total += 1;}else if(temp.r < path[i].r) {if(path[i].c >= temp.c) {path[i].f = 1;temp = path[i];total += 1;}}}}}printf("%d\n", step);n = 0;} else {path[n].r = r;path[n].f = 0;path[n++].c = c;}}return 0;}
- ZOJ-1756 Robots
- zoj 1654 Place the Robots
- zoj 1654 Place the Robots
- zoj 1654 Place the Robots
- ZOJ 1654 Place the Robots
- Place the Robots zoj 1654
- ZOJ 1654 Place the Robots
- ZOJ 1654 Place the Robots
- [ZOJ 3052] Unix Robots [模拟]
- ZOJ 1654 Place the Robots
- ZOJ 1654 Place the Robots
- 【二分匹配】ZOJ 1654 Place the Robots
- ZOJ 1654 Place the Robots DINIC
- ZOJ 1654 Place the Robots (二分匹配 )
- ZOJ 1654 Place the Robots(最大二分匹配)
- zoj 1654 Place the Robots - Hungary 经典之作 - 绝佳好题
- ZOJ 1654 Place the Robots(二分图最大匹配)
- zoj 1654 Place the Robots (二分图匹配)
- WglCreateContext 函数详解
- CareerCup-4.2
- 互芯最新资料大全
- 可靠数据传输的原理:比特差错
- UVA 539 - The Settlers of Catan
- ZOJ-1756 Robots
- 多线程编程之————条件变量
- 司马憙:宫女难除,举为王后
- 彻底解决Win7无线网络连接问题,无法连接不用怕
- 对图像滤波的理解
- 免费的线框的套件 - Wired 1.0
- osgi via two dependency chains 异常
- 文学 2013年5月10日 22:10:34更新
- MongoDB的真正性能-实战百万用户一-一亿的道具