Soul Gem Bzoj 2663

Source: Internet
Author: User

Soul gem (1s 128MB) soulgem

"Problem description"

"As the soul of your body, in order to be able to better use the magic, has been given a small and safe form ..."

We know that the life of a magical maiden is stored in a device called Soul Gem (Soul Gem). And sometimes, when the soul Jewel is farther away from the body, the magical girl is unable to control her body.

In legend, the Magic Maiden Abel the general law of this phenomenon only by inference, known as the Abel Theorem: the existence of the cosmological constant R (a nonnegative real, or positive infinity), known as the Soul Gem constant, dimensional

Is the space measure (that is, the length). If a magical girl's soul gem is closer to her body than R, she must not be able to control her body; if the distance is strictly less than R, she must be able to control

To make their own bodies. (The distance here refers to the Euclid distance of the plane.) )

Note: This theorem cannot predict a situation where the distance is just R. There may be magical girls A and B, and they are exactly r from their soul gems, but a can control their bodies, and B cannot.

There are no more magic girls in the world now, but we are interested in this cosmic constant. We can only use the data left over from the previous world to determine the scope of this constant.

Each group of data contains the following information:

There are a total of N magical girls and their soul gems, numbered 1-n.

The location of these n magical Girls is (Xi, Yi).

The location of these n Soul Gems is (xi, Yi).

At this time, there are just K magic girls can control their own body.

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

2. The correspondence between magical girls and soul gems is unknown.

3. We do not know exactly which of the K magic Girls are able to control their bodies.

Based on the above information, you need to determine the possible minimum Rmin and maximum rmax of the Soul Gem constant R.

"Input Format"

The first row of packets is two integers: N, K.
Next n rows, each line contains two integers: xi,yi, separated by spaces.
Next n rows, each line contains two integers: xi,yi, separated by spaces.

"Output Format"

Output two volume: Rmin, Rmax, separated by a space in the middle.
Rmin must be a nonnegative real number rounded to two digits after the decimal point.
Rmax may be nonnegative real or positive infinity:
If the nonnegative real number is rounded to two digits after the decimal point;
If it is positive infinity, the output is "+inf" (without quotation marks).

"Input Sample"

2 1

1 0

4 0

0 0

4 4

"Output Example"

1.00 5.00

"Data Range"

For 100% of data:

1≤n≤50,0≤k≤n, -1000≤xi,yi,xi,yi≤1000.

Exercises

The main algorithm: binary graph matching or network flow, two points;

Test instructions: for n individuals and N gems, each individual needs to match 11 gems with distances less than k, and gems with a distance equal to K are free to choose whether or not to match, seeking the minimum and maximum values of K

Then the minimum value can be easily thought of two points, connecting all the distance is less than k edge, with the binary graph matching test, then the maximum match number to find the minimum value

However, the maximum value can not be solved directly as the minimum value, because the binary graph is the maximum match, the simulation example can be

So consider a little bit of transformation

The maximum value of the test, we will distance is greater than or equal to K of the edge connected

Then the result of the binary graph matching run out is the maximum number of mismatches

The total number minus the maximum number of mismatches is the minimum number of matches

As long as we use the minimum number of matches , we can find the maximum value .

1#include <algorithm>2#include <iostream>3#include <cstring>4#include <cstdlib>5#include <cstdio>6#include <cmath>7 using namespacestd;8 structShape9 {Ten     Doublex, y; One }; A intN, K; - DoubleL, R; - Doubleans; the intmy[233]; -Shape a[233]; - BOOLvis[233]; - intTot, to[10233], nex[10233], fir[233]; +InlineDoubleDis (Shape x, shape y) - { +     returnsqrt ((x.x-y.x) * (x.x-y.x) + (X.Y-Y.Y) * (X.Y-y.y)); A } atInlinevoidIns (intXinty) - { -Nex[++tot] =Fir[x]; -FIR[X] =tot; -To[tot] =y; - } in BOOLFind (intu) - { to      for(inti = Fir[u]; I i =Nex[i]) +     { -         intv =To[i]; the         if(!Vis[v]) *         { $VIS[V] =true; Panax Notoginseng             if(!my[v] | |Find (My[v])) -             { theMY[V] =u; +                 return true; A             } the         } +     } -     return false; $ } $InlineBOOLCheckmi (Doublex) - { -tot =0; the      for(inti =1; I <= N; ++i) My[i + n] = fir[i] =0; -      for(inti =1; I <= N; ++i)Wuyi          for(intj = n +1; J <= N + N; ++j) the             if(Dis (A[i], a[j]) <=x) - Ins (i, j); Wu     intsum =0; -      for(inti =1; I <= N; ++i) About     { $          for(intj =1; J <= N; ++j) -Vis[j + N] =false; -         if(Find (i)) + +sum; -     } A     if(Sum < k)return true; +     return false; the } -InlineBOOLCheckma (Doublex) $ { thetot =0; the      for(inti =1; I <= N; ++i) My[i + n] = fir[i] =0; the      for(inti =1; I <= N; ++i) the          for(intj = n +1; J <= N + N; ++j) -             if(Dis (A[i], a[j]) >=x) in Ins (i, j); the     intsum =0; the      for(inti =1; I <= N; ++i) About     { the          for(intj =1; J <= N; ++j) theVis[j + N] =false; the         if(Find (i)) + +sum; +     } -     if(Sum < N-K)return false; the     return true;Bayi } the intMain () the { - //freopen ("soulgem.in", "R", stdin), Freopen ("Soulgem.out", "w", stdout); -scanf"%d%d", &n, &k); the      for(inti =1; I <= n + N; ++i) thescanf"%LF%LF", &a[i].x, &a[i].y); theL =0, r =3666; the      for(inti =1; I <= -; ++i) -     { the         DoubleMi = (l + r)/2.0; the         if(Checkmi (mi)) L =mi; the         ElseAns = mi, r =mi;94     } theprintf"%.2LF", ans); theAns =3666; theL =0, r =3666;98      for(inti =1; I <= -; ++i) About     { -         DoubleMi = (l + r)/2.0;101         if(Checkma (mi)) ans = mi, l =mi;102         ElseR =mi;103     }104     if(Fabs (ANS-3666) <=0.001) printf ("+inf"); the     Elseprintf"%.2LF", ans);106}

Soul Gem Bzoj 2663

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.