1. 程式人生 > >Codeforces 935 C Fifa and Fafa

Codeforces 935 C Fifa and Fafa

span 中心 col printf style first sqrt 範圍 流浪

935 C

題意:Fifa想用wifi下載足球遊戲, 但是Fafa是個流浪狂魔, 所以Fifa想讓他的wifi在公寓裏盡量覆蓋最大的面積,並且不覆蓋到Fafa和公寓外的人,fafa的坐標可以在公寓外。

題解:求半徑最大的地方就好了, 這個半徑最大的位置一定在Fafa和公寓中心的連線上(前提是Fafa不和公寓中心重合且fafa在公寓範圍內)。

代碼:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define LL long long
 4 #define fi first
 5 #define se second
 6
#define lson l,m,rt<<1 7 #define rson m+1,r,rt<<1|1 8 #define max3(a,b,c) max(a,max(b,c)) 9 const int INF = 0x3f3f3f3f; 10 typedef pair<int,int> pll; 11 int main() 12 { 13 double r, x1, y1, x2, y2; 14 cin >> r >> x1 >> y1 >> x2 >> y2; 15 double
l = sqrt(pow(x1-x2,2)+ pow(y1-y2,2)); 16 if(l == 0)//重合 17 { 18 printf("%.7f %.7f %.7f", x1+r/2, y1, r/2); 19 return 0; 20 } 21 if(l > r)//在公寓外 22 { 23 printf("%.7f %.7f %.7f", x1, y1, r); 24 return 0; 25 } 26 double Sin = (y1-y2) / l; 27 double
Cos = (x1-x2) / l; 28 double ll = (l+r)/2; 29 double ansy = y2 + Sin * ll; 30 double ansx = x2 + Cos * ll; 31 printf("%.7f %.7f %.7f\n",ansx, ansy, ll); 32 return 0; 33 }

Codeforces 935 C Fifa and Fafa