HDU + 2295 + dancing + link ++

Source: Internet
Author: User
# Include <stdio. h> # include <string. h >#include <cmath> # define N 60 # define v n * N int L [V], R [V]; // record the two-way linked list int U [V], D [V]; // record the two-way linked list int C [V]; // The address int H [N] pointing to its column pointer header; // The row pointer header int S [N]; // records the total number of nodes in the column linked list int size, n, m, ak; int mark [N] [N], visit [N]; const double eps = 1e-7; void prepare (int c) {for (int I = 0; I <= c; I ++) {S [I] = 0; U [I] = D [I] = I; L [I + 1] = I; R [I] = I + 1;} R [c] = 0; size = c + 1; memset (H,-1, sizeof (H);} voi D Link (int r, int c) {S [c] ++; C [size] = c; U [size] = U [c]; D [U [c] = size; D [size] = c; U [c] = size; if (H [r] =-1) H [r] = L [size] = R [size] = size; else {L [size] = L [H [r]; R [L [H [r] = size; R [size] = H [r]; L [H [r] = size;} size ++ ;} void remove (int Size) {int j; for (j = D [Size]; j! = Size; j = D [j]) L [R [j] = L [j], R [L [j] = R [j];} void resume (int Size) {int j; for (j = D [Size]; j! = Size; j = D [j]) L [R [j] = R [L [j] = j;} int h () {int count = 0, i, j, k; memset (visit, 0, sizeof (visit); for (I = R [0]; I = R [I]) {if (visit [I]) continue; count ++; for (j = D [I]; j! = I; j = D [j]) {for (k = R [j]; k! = J; k = R [k]) visit [C [k] = 1;} return count;} void Dance (int k) {int I, j, min, c; if (k + h ()> = ak) return; if (! R [0]) {if (k <ak) ak = k; return;} for (min = N, I = R [0]; I; I = R [I]) if (min> S [I]) min = S [I], c = I; for (I = D [c]; I! = C; I = D [I]) {remove (I); for (j = R [I]; j! = I; j = R [j]) remove (j); Dance (k + 1); for (j = R [I]; j! = I; j = R [j]) resume (j); resume (I) ;}} struct point {double x, y;} rar [55], city [55]; double dis (point a, point B) {return sqrt (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} int main () {int ca, k, K; scanf ("% d", & ca); while (ca --) {scanf ("% d", & n, & m, & K); for (int I = 1; I <= n; I ++) scanf ("% lf", & city [I]. x, & city [I]. y); for (int I = 1; I <= m; I ++) scanf ("% lf", & rar [I]. x, & rar [I]. y); double L = 0, R = 10000, mid; while (R-L> eps) {prepare (n); mid = (R + L)/2.0; for (int I = 1; I <= m; I ++) {for (int j = 1; j <= n; j ++) {if (dis (rar [I], city [j]) <mid + eps) Link (I, j) ;}} ak = N + 1; Dance (0 ); // printf ("% d ###\ n", ak); if (ak> K) {L = mid;} else {R = mid ;}} printf ("%. 6lf \ n ", R);} 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.