Poj1548--robots

Source: Internet
Author: User

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

Description

Your Company provides robots, can be used to pick up litter from fields after sporting events and concerts. Before robots was assigned to a job, an aerial photograph of the field was marked with a grid. Each of the contains garbage is marked. All robots begin with the northwest corner and end their movement in the southeast corner. A robot can only move in and directions, either to the East or south. Upon entering a cell that contains garbage, the robot would pick it up before proceeding. Once a robot reaches its destination at the southeast corner it cannot be repositioned or reused. Since your expenses is directly proportional to the number of robots used for a particular job, you is interested in fin Ding the minimum number of robots so 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, the all robots would begin in the location of the and end in Location 6, 7. 

Figure 1-a Field Map
Figure 2 below shows-possible solutions, the second of which is preferable since it uses both robots rather than three.

Figure 2-two Possible Solutions
Your task is to create a program that would 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 sign Al the end of the map. Each garbage location consists of both integers, the row and column, separated by a single space. The rows and columns is numbered as shown in Figure 1. The garbage locations is given in row-major order. No single field map would have the more than rows and columns. The sample input below shows an input file with a field maps. The first is the field map from Figure 1.

Output

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

Sample Input

1 21 42 42 64 44 76 60 01 12 24 40 0-1-1

Sample Output

2 1

Source

Mid-Central USA 2003//mainly find out the key meaning; as long as the existence of the minimum number of partitions so that each partition within the two-tuple will meet X1 <= x2 and y1 <= y2: Dirworth theorem
1#include <stdio.h>2#include <algorithm>3 using namespacestd;4 5 structField6 {7     inth;8     intZ;9 } ;TenField num[ -] ; One  A BOOLcmp (field H,field z)/* - { -     if(H.H = =z.h) the     returnH.z <z.z; -     Else -     returnH.H <z.h; /* - } +  -  + intMain () A { at     intm,n,i; -      while(~SCANF ("%d%d", &num[0].h, &num[0].Z), (num[0].h!=-1, num[0].z!=-1)) -     { -          for(i=1;; i++) -         { -scanf"%d%d", &num[i].h, &num[i].z); in             if(!num[i].h,!)num[i].z) -              Break; to         } +Sort (num, num+I, CMP); -         intTemp, J, K, total=0 ; the          for(j=0; j<i; J + +*/* Not first traverse, after statistics! 0 numbers, not optimal; *         { $             if(Num[j].z! =0)Panax Notoginseng             { -temp =num[j].z; thetotal++; +                  for(k=j+1; k<i; k++) A                 { the                     if(Num[k].z >=temp) +                     { -temp=num[k].z; $Num[k].z =0 ; $                     } -                 } -             } the              -         }                                /*Wuyiprintf"%d\n", total); the     } -     return 0 ; Wu}

Poj1548--robots

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.