Codeforces Round #465 (Div. 2) Fifa and Fafa

C. Fifa and Fafa
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of r meters (this range can be chosen by Fifa) from its position. Fifa must put the access point inside the flat which has a circular shape of radius R. Fifa wants to minimize the area that is not covered by the access point inside the flat without letting Fafa or anyone outside the flat to get access to the internet.

The world is represented as an infinite 2D plane. The flat is centered at (x1, y1) and has radius R and Fafa's laptop is located at (x2, y2), not necessarily inside the flat. Find the position and the radius chosen by Fifa for his access point which minimizes the uncovered area.

Input

The single line of the input contains 5 space-separated integers R, x1, y1, x2, y2 (1 ≤ R ≤ 105, |x1|, |y1|, |x2|, |y2| ≤ 105).

Output

Print three space-separated numbers xap, yap, r where (xap, yap) is the position which Fifa chose for the access point and r is the radius of its range.

Your answer will be considered correct if the radius does not differ from optimal more than 10 - 6 absolutely or relatively, and also the radius you printed can be changed by no more than 10 - 6 (absolutely or relatively) in such a way that all points outside the flat and Fafa's laptop position are outside circle of the access point range.

Examples
input
Copy
5 3 3 1 1
output
3.7677669529663684 3.7677669529663684 3.914213562373095
input
Copy
10 5 5 5 15
output
5.0 5.0 10.0

 

 一道数学题

但是想练练模拟退火,万幸的A了,如果wrong answer了,就把m写大点儿~ 逃~~~~

 1 #include<iostream>
 2 using namespace std;
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cstdlib>
 6 #include<ctime>
 7 #include<cmath>
 8 typedef long long LL;
 9 double T;
10 double R,x1,x2,yy1,y2;
11 const int M = 20;
12 double ax[M],ay[M],dr[M];
13 /*inline long long randt(){
14     static long long seed = 2333;
15     return seed = (long long)((((seed ^ 998244353) + 19260817ll) * 19890604ll) % 10000000000000007);
16 }*/
17 double Getrand(){
18     double ans = rand();
19 //    cout<<ans<<endl;
20     ans/=RAND_MAX;
21     if(rand()%2)
22         ans*=-1.0;
23     ans*=3.145926535;
24     return ans;
25 }
26 double get_dis(double x1,double yy1,double x2,double y2){
27     double d1 = x1-x2;
28     double d2 = yy1-y2;
29     return sqrt(d1*d1+d2*d2);
30 }
31 double get(double X,double Y){
32     double r1 = R-get_dis(x1,yy1,X,Y);
33     double r2 = get_dis(x2,y2,X,Y);
34     double r = r1;
35     if(r>r2)
36         r=r2;
37     return r;
38 }
39 int main(){
40     srand(time(0));
41     scanf("%lf%lf%lf%lf%lf",&R,&x1,&yy1,&x2,&y2);
42     for(int i=0;i<M;i++){
43         ax[i]=Getrand()*R+x1;
44         ay[i]=Getrand()*R+yy1;
45         dr[i]=get(ax[i],ay[i]);
46     }
47     T=1.2*R;
48     while(T>0.000009){
49         for(int i=0;i<M;i++){
50             for(int j=0;j<500;j++){
51             double nx,ny,nd;
52             double pp =Getrand() ,qq=Getrand();
53             nx = cos(Getrand())*T+ax[i];
54             ny = sin(Getrand())*T+ay[i];
55             if(get_dis(x1,yy1,nx,ny)>R)
56                 continue;
57             nd = get(nx,ny);
58         //    cout<<nx<<" "<<ny<<" "<<nd<<" "<<pp<<" "<<qq<<" "<<T<<endl;
59         //    getchar();
60             if(nd>dr[i]){
61                 dr[i]=nd;
62                 ax[i]=nx;
63                 ay[i]=ny;
64                 continue;
65             }
66             else{
67                  int p=rand()%10000;
68                  if(p<=50){
69                     dr[i]=nd;
70                     ax[i]=nx;
71                     ay[i]=ny;
72                     continue;    
73                  }
74             }
75             }
76         }
77         T*=0.9;
78     }
79     double ansx=ax[0],ansy=ay[0],ansr=dr[0];
80     for (int i=1;i<M;i++){
81         if(ansr<dr[i]){
82             ansx=ax[i],ansy=ay[i],ansr=dr[i];
83         }
84     }
85     printf("%.10f %.10f %.10f",ansx,ansy,ansr);
86     return 0;
87 }

 

posted @ 2018-03-09 10:25  晓风微微  阅读(295)  评论(0编辑  收藏  举报