Soul gem bzoj 2663, bzoj2663

Source: Internet
Author: User

Soul gem bzoj 2663, bzoj2663

Soul gem (1 s 128 MB) soulgem

[Problem description]

"As the soul of your body, in order to better use magic, you have been given a small and safe shape ······"

We know that the life of a magic girl is stored in a device called Soul Gem. Sometimes, when the soul gem is far away from the body, the magic girl cannot control her own body.

In the legend, the magic girl Abel only obtains the general law of this phenomenon through reasoning. It is called the Abel Theorem: existence of a cosmic constant R (a non-negative real number or a positive infinity ), it is called the constant and dimension of the soul gem.

Is a space measurement (that is, length ). If the distance between a magic girl's soul gem and her body exceeds R, she cannot control her own body. If the distance is strictly less than R, she will be able to control it.

Create your own body. (The distance here refers to the Euclid Distance of the plane .)

Note: The theorem cannot predict the distance is R. There may be magic girls A and B. The distance between them is exactly R, but A can control their bodies, while B cannot.

Now there is no magic girl in this world, but we are interested in this cosmic constant. We can only determine the scope of this constant through the data left over from the world.

Each group of data contains the following information:

A total of N magic girls and their soul gems are numbered 1-N.

The locations of the N magic girls are (Xi, Yi ).

The position of these N soul gems is (xi, yi ).

At this point, K magic girls can control their bodies.

1. We think the world is a two-dimensional Euclid space.

2. The relationship between the magic girl and the soul gem is unknown.

3. We don't know which K magic girls can control their bodies.

Based on the above information, you need to determine the possible minimum Rmin and maximum Rmax values of the soul gem constant R.

[Input format]

The first line contains two integers: N and K.
In the next N rows, each line contains two integers: Xi and Yi, separated by spaces.
Next N rows, each line contains two integers: xi, yi, separated by spaces.

[Output format]

Two outputs: Rmin and Rmax, separated by spaces.
Rmin must be a non-negative real number, rounded to the second digit after the decimal point.
Rmax may be a non-negative real number or a positive infinity:
If it is a non-negative real number, it is rounded to the second digit after the decimal point;
If it is positive infinity, "+ INF" is output (excluding quotation marks ).

[Input example]

2 1

1 0

4 0

0 0

4

[Output example]

1.00 5.00

[Data Scope]

For 100% of data:

1 ≤ N ≤ 50, 0 ≤ K ≤ N,-1000 ≤ xi, yi, Xi, Yi ≤ 1000.

 

Question:

Main algorithms: bipartite graph matching or network stream; Bipartite Graph Matching;

For n people and n gems, each person needs to match a gem whose distance is less than k. A gem whose distance is equal to k can choose whether to match, evaluate the minimum and maximum values of k

Then the minimum value can easily be thought of as binary. Connect all edges with a distance less than k and use the Bipartite Graph Matching Test to obtain the minimum value using the maximum matching number.

However, the maximum value cannot be solved just like the minimum value. Because the bipartite graph is used to obtain the maximum matching, the simulation sample can be obtained.

So consider a small conversion.

In the maximum value test, we connect an edge with a distance greater than or equal to k.

Then, the result of bipartite graph matching is the maximum number of unmatched results.

The total number minus the maximum number of non-matching is the minimum number of matching.

The maximum value can be obtained by using the minimum matching number.

 

  1 #include<algorithm>  2 #include<iostream>  3 #include<cstring>  4 #include<cstdlib>  5 #include<cstdio>  6 #include<cmath>  7 using namespace std;  8 struct shape  9 { 10     double x, y; 11 }; 12 int n, k; 13 double l, r; 14 double ans; 15 int my[233]; 16 shape a[233]; 17 bool vis[233]; 18 int tot, to[10233], nex[10233], fir[233]; 19 inline double Dis(shape x, shape y) 20 { 21     return sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y)); 22 } 23 inline void Ins(int x, int y) 24 { 25     nex[++tot] = fir[x]; 26     fir[x] = tot; 27     to[tot] = y; 28 } 29 bool Find(int u) 30 { 31     for(int i = fir[u]; i; i = nex[i]) 32     { 33         int v = to[i]; 34         if(!vis[v]) 35         { 36             vis[v] = true;  37             if(!my[v] || Find(my[v])) 38             { 39                 my[v] = u; 40                 return true; 41             } 42         } 43     } 44     return false; 45 } 46 inline bool Checkmi(double x) 47 { 48     tot = 0; 49     for(int i = 1; i <= n; ++i) my[i + n] = fir[i] = 0; 50     for(int i = 1; i <= n; ++i) 51         for(int j = n + 1; j <= n + n; ++j) 52             if(Dis(a[i], a[j]) <= x) 53                 Ins(i, j); 54     int sum = 0; 55     for(int i = 1; i <= n; ++i) 56     { 57         for(int j = 1; j <= n; ++j) 58             vis[j + n] = false; 59         if(Find(i)) ++sum; 60     } 61     if(sum < k) return true; 62     return false; 63 } 64 inline bool Checkma(double x) 65 { 66     tot = 0; 67     for(int i = 1; i <= n; ++i) my[i + n] = fir[i] = 0; 68     for(int i = 1; i <= n; ++i) 69         for(int j = n + 1; j <= n + n; ++j) 70             if(Dis(a[i], a[j]) >= x) 71                 Ins(i, j); 72     int sum = 0; 73     for(int i = 1; i <= n; ++i) 74     { 75         for(int j = 1; j <= n; ++j) 76             vis[j + n] = false; 77         if(Find(i)) ++sum; 78     } 79     if(sum < n - k) return false; 80     return true; 81 } 82 int main() 83 { 84 //    freopen("soulgem.in", "r", stdin), freopen("soulgem.out", "w", stdout); 85     scanf("%d%d", &n, &k); 86     for(int i = 1; i <= n + n; ++i) 87         scanf("%lf %lf", &a[i].x, &a[i].y); 88     l = 0, r = 3666; 89     for(int i = 1; i <= 38; ++i) 90     { 91         double mi = (l + r) / 2.0; 92         if(Checkmi(mi)) l = mi; 93         else ans = mi, r = mi; 94     } 95     printf("%.2lf ", ans); 96     ans = 3666; 97     l = 0, r = 3666; 98     for(int i = 1; i <= 38; ++i) 99     {100         double mi = (l + r) / 2.0;101         if(Checkma(mi)) ans = mi, l = mi;102         else r = mi;103     }104     if(fabs(ans - 3666) <= 0.001) printf("+INF");105     else printf("%.2lf", ans);106 }

 

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.