HDU 4462 scaring the birds 37th ACM/ICPC Hangzhou division J question (simple question)

Source: Internet
Author: User
Scaring the birds

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 20 accepted submission (s): 10

Problem descriptionit's harvest season now!
Farmer John plants a lot of corn. there are missing birds living around his corn field. these birds keep stealing his corn all the time. john can't stand with that any more. he decides to put some scarecrows in the field to drive the birds away.
John's field can be considered as an n × n grid which has n × n intersections. john plants his corn on every intersection at first. but as time goes by, some corn were destroyed by rats or birds so some vacant intersections were left. now John wants to put scarecrows on those vacant intersections and he can put at most one scarecrow on one intersection. because of the landform and the different height of corn, every vacant intersections has a scaring range R meaning that if John put a scarecrow on it, the scarecrow can only scare the birds inside the range of Manhattan distance R from the intersection.

The figure above shows a 7 × 7 Field. assuming that the scaring range of vacant intersection (4, 2) is 2, then the corn on the marked intersections can be protected by a scarecrow put on intersection (4, 2 ).
Now John wants to figure out at least how should he scarecrows he must buy to protect all his corn.

 

Inputthere are several test cases.
For each test case:
The first line is an integer N (2 <= n <= 50) meaning that John's field is an n × n grid.
The second line is an integer K (0 <= k <= 10) meaning that there are K vacant intersections on which John can put a scarecrow.
The third line describes the position of K vacant intersections, in the format of R1, C1, R2, C2 .... Rk, CK. (Ri, CI) is the position of the I-th intersection and 1 <= R1, C1, R2, C2 .... Rk, CK <= n.
The forth line gives the scaring range of all vacant intersections, in the format of R1, R2... Rk and 0 <= R1, R2... Rk <= 2 × n.
The input ends with n = 0.

 

Outputfor each test case, print the minimum number of scarecrows Farmer John must buy in a line. If John has no way to protect all the corn, print-1 instead.

 

Sample input4 2 2 3 3 3 3 4 2 2 3 3 1 4 0

 

Sample output-1 1

 

Source2012 Asia Hangzhou Regional Contest Simple question. But there are traps. It does not need to overwrite the points that can be placed. And the answer may be 0, that is, when N * n points are put. Compress the data according to the status to perform enumeration.
 //  ========================================================== ==========================================  //  Name: hdu4462.cpp  //  Author:  //  Version:  //  Copyright: Your copyright notice  //  Description: Hello world in C ++, ANSI-style //  ========================================================== ==========================================  # Include <Iostream> # Include <Stdio. h> # Include <Algorithm> # Include < String . H> # Include <Math. h> Using   Namespace  STD;  Const   Int Maxn =60  ;  Int R [ 12 ], C [ 12  ];  Int R [ 12  ];  Bool  F [maxn] [maxn];  Int A [ 12  ];  Int  Main (){ Int  N;  Int  K;  While (Scanf ( "  % D  " , & N) = 1 && N) {scanf (  "  % D  " ,& K );  For ( Int I = 0 ; I <K; I ++ ) Scanf (  "  % D  " , & R [I], & C [I]);  For ( Int I = 0 ; I <K; I ++ ) Scanf (  "  % D  " ,& R [I]); Int Ans = 1000000  ;  Int M = ( 1 < K );  For ( Int S = 0 ; S <m; s ++ ){  Int Num = 0  ;  For (Int I = 0 ; I <K; I ++ )  If (S &( 1 < I) {A [num ++] = I;} memset (F,  False , Sizeof  (F ));  Bool Flag = True  ; For ( Int I = 1 ; I <= N; I ++ )  For ( Int J = 1 ; J <= N; j ++ ){  For ( Int X = 0 ; X <K; X ++ )  If (I = R [x] & J =C [x]) f [I] [J] = True  ;  If (F [I] [J]) Continue  ;  For ( Int X = 0 ; X <num; X ++ ){  If (ABS (I-r [A [x]) + ABS (J-C [A [x]) <= R [A [x]) {f [I] [J] =True  ;  Break  ;}}  If (F [I] [J] = False ) Flag = False  ;  If (! Flag) Break  ;}  If (! Flag) Continue ; Ans = Min (ANS, num );}  If (ANS> 1000 ) Ans =- 1  ; Printf (  "  % D \ n  "  , ANS );}  Return   0  ;} 

 

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.