HDU 2295 Dance chain can be repeated overlay + two points

Source: Internet
Author: User

Click to open link

Test instructions: gives n points and m centers, in the case of not more than K circle, so that all points are covered, the smallest radius of the circle of how much

Train of thought: Ask the smallest what what then use two quasi-accurate, then what is the second condition, is to use not more than K of the circle can all points covered, covering this part is the naked dance chain can be repeated coverage, behavior M Circle, listed as N points, and then find the minimum line less than or equal to K, then set up, or not

#include <math.h> #include <vector> #include <stdio.h> #include <string.h> #include < stdlib.h> #include <iostream> #include <algorithm>using namespace std;typedef long Long ll;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const ll inf=0x3f3f3f3f3f3f3f3fll;const int Maxn=310;const double eps=1e- 8;int l[maxn*maxn],r[maxn*maxn],u[maxn*maxn],d[maxn*maxn];//node up and down four-way linked list int C[maxn*maxn],h[maxn],cnt[maxn],vis [maxn];//c column h row CNT list number of elements int n,m,id,fans,k;void init (int lll) {for (int i=0;i<=lll;i++) {cnt[i]=0;        U[i]=d[i]=i; L[i+1]=i;    r[i]=i+1;    } r[lll]=0;id=lll+1; memset (h,-1,sizeof (H)); void Link (int r,int c) {cnt[c]++;    C[id]=c;    U[ID]=U[C];D [U[c]]=id; D[id]=c;    U[c]=id;    if (h[r]==-1) H[r]=l[id]=r[id]=id; else{L[id]=l[h[r]];        R[l[h[r]]]=id; R[ID]=H[R];    L[h[r]]=id; } id++;} void Remove (int Size) {for (int j=d[size];j!=size;j=d[j]) l[r[j]]=l[j],r[l[j]]=r[j];} void Resume (int Size) {for (intJ=D[SIZE];J!=SIZE;J=D[J]) L[r[j]]=r[l[j]]=j;}    int h () {int sum=0;    memset (vis,0,sizeof (VIS));        for (int i=r[0];i;i=r[i]) {if (vis[i]) continue;        sum++;        For (int. J=d[i];j!=i;j=d[j]) {for (int k=r[j];k!=j;k=r[k]) vis[c[k]]=1; }} return sum;}    void Dance (int k) {int mm=maxn,pos;    if (K+h () >=fans) return; if (!        R[0]) {if (K<fans) fans=k;    Return    } for (int i=r[0];i;i=r[i]) if (mm>cnt[i]) mm=cnt[i],pos=i;        for (int i=d[pos];i!=pos;i=d[i]) {Remove (i);        for (int j=r[i];j!=i;j=r[j]) Remove (j);        Dance (k+1);        for (int j=r[i];j!=i;j=r[j]) Resume (j);    Resume (i);    }}int a[110][2],b[110][2];d ouble calcdis (int i,int j) {Double ttt= (a[i][0]-b[j][0]) * (a[i][0]-b[j][0]);    Double ppp= (a[i][1]-b[j][1]) * (a[i][1]-b[j][1]);    Double ans=sqrt (TTT+PPP); return ans;}    BOOL Judge (double mid) {init (n); fans=k+1; for (int i=1;i<=n;i++) {for (int j=1;j<=m;j++) {double Ttt=calcdis (i,j);        if (ttt<=mid) Link (j,i);    }} Dance (0);    if (fans<=k) return 1; else return 0;}    int main () {int T;    scanf ("%d", &t);        while (t--) {scanf ("%d%d%d", &n,&m,&k);        for (int i=1;i<=n;i++) scanf ("%d%d", &a[i][0],&a[i][1]);        for (int i=1;i<=m;i++) scanf ("%d%d", &b[i][0],&b[i][1]);        Double le=0,ri=10000.0;            while (ri-le>eps) {double mid= (Le+ri)/2;            if (judge (mid)) Ri=mid;        else Le=mid;    } printf ("%.6lf\n", RI); } return 0;}

HDU 2295 Dance chain can be repeated overlay + two points

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.