[ACM] HDU 2295 radar (dual + DLX)

Source: Internet
Author: User
Tags radar
Radar

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


Problem description

N cities of the Java Kingdom need to be covered by Radars for being in a state of war. since the Kingdom has m radar stations but only K operators, we can at most operate K radars. all radars have the same circular coverage with a radius of R. our goal is to minimize R while covering the entire city with no more than K radars.


Input

The input consists of several test cases. the first line of the input consists of an integer T, indicating the number of test cases. the first line of each test case consists of 3 integers: n, m, K, representing the number of cities, the number of radar stations and the number of operators. each of the following n lines consists of the coordinate of a city.
Each of the last M lines consists of the coordinate of a radar station.

All coordinates are separated by one space.
Technical Specification

1. 1 ≤ T ≤ 20
2. 1 ≤ n, m ≤ 50
3. 1 ≤ k ≤ m
4. 0 ≤ x, y ≤ 1000


Output

For each test case, output the radius on a single line, rounded to six fractional digits.


Sample Input

13 3 23 43 15 41 12 23 3


Sample output

2.236068


Source

The 4th Baidu Cup Final

Solution:

There are m radars. The coverage of each radar is a circle with the R radius. Given their coordinates, there are n cities, given their coordinates, and finding the smallest R, in this way, each city is covered by a radar, with a maximum of K radars working.

The second answer is R. Determine whether the radar number is smaller than the given K and find the smallest R.

It is determined by repeated DLX overwrites. First, create a map: m rows, n columns of rectangles, that is, the horizontal coordinates represent the radar, and the vertical coordinates represent the city. if the distance between the Radar and the city is less than or equal to the current R, then, the coordinates are marked as 1; otherwise, it is 0, which is converted to the 01 matrix, that is, whether the problem can be solved to find some rows in the matrix (the number of rows is less than or equal to K ), make the new matrix composed of these rows, each column has at least one (repeated overwrite, each column can have more than one ).

For precise coverage and repeated coverage, the following is reproduced in: http://www.cnblogs.com/jh818012/p/3252154.html

Precise coverage:
First, select the column to be overwritten (including the least one column), remove the column and all the rows that can be overwritten by the column, and then enumerate the method to add.
Enumerate a row of R. If it is a solution set, all columns that can be covered by the row do not need to be searched. Therefore, all columns covered by the row are deleted, because the removed columns are equivalent to solutions, you do not need to search or delete the rows that can overwrite these columns.
Duplicate coverage:
First, select the column to be overwritten (same as above) and delete the column. Enumeration overwrites all the rows in the column: for a row of R, assume that it is a solution set, therefore, you do not need to search for the columns that can be overwritten by this row. Therefore, you can delete all columns that are overwritten by this row.
Note that you do not need to delete the rows that overwrite these columns, because one column can have multiple 1.
Here is an optimization of a *: The estimation function H indicates that several edges need to be added to overwrite the current state.

Code:

# include # include # include # include # include # include # include # include # include # include # include # include using namespace STD; const int maxn = 52; const int maxm = 52; const int maxnode = 3020; int n, m, K; struct DLX {int n, m, size; int U [maxnode], d [maxnode], R [maxnode], L [maxnode], row [maxnode], Col [maxnode]; I Nt h [maxn], s [maxn]; int anSd, ANS [maxn]; void Init (INT _ n, int _ m) {n = _ N; M = _ m; For (INT I = 0; I <= m; I ++) {s [I] = 0; U [I] = d [I] = I; L [I] = I-1; R [I] = I + 1;} R [m] = 0, L [0] = m; size = m; For (INT I = 1; I <= N; I ++) H [I] =-1 ;} void Link (int r, int c) {++ s [col [++ size] = C]; row [size] = R; d [size] = d [c]; U [d [c] = size; U [size] = C; d [c] = size; if (H [R] <0) H [R] = L [size] = R [size] = size; else {R [size] = R [H [R]; L [R [H [R] = size; L [size] = H [R ]; R [H [R] = size ;}} void remove (INT c) {for (INT I = d [c]; I! = C; I = d [I]) L [R [I] = L [I], R [L [I] = R [I];} void resume (INT c) {for (INT I = U [c]; I! = C; I = U [I]) L [R [I] = R [L [I] = I;} bool V [maxnode]; int F () // exact coverage estimation pruning {int ret = 0; For (INT c = R [0]; C! = 0; C = R [c]) V [c] = true; For (INT c = R [0]; C! = 0; C = R [c]) if (V [c]) {RET ++; V [c] = false; For (INT I = d [c]; i! = C; I = d [I]) for (Int J = R [I]; J! = I; j = R [J]) V [col [J] = false;} return ret;} bool Dance (INT d) {If (D + f ()> k) return false; If (D> K) return false; If (R [0] = 0) return true; int c = R [0]; for (INT I = R [0]; I! = 0; I = R [I]) if (s [I] = EPS) {double mid = (L + r)/2.0; G. init (n, m); For (INT I = 1; I <= N; I ++) for (Int J = 1; j <= m; j ++) if (DIS (radar [I], City [J])


[ACM] HDU 2295 radar (dual + DLX)

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.