Home BOJ. Two Circles (1069)
Post
Cancel

BOJ. Two Circles (1069)

[Link] https://www.acmicpc.net/problem/1069


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <stack>
#include <cmath>
// #include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define command_param int argc, char *argv[]
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i < n; i++)
#define fori(s, e) for(int i = s; i < e; i++)
#define ll long long
#define endl "\n"
#define nulls '\0'
#define dkdk " "
const int MAX = 2002;
const int INF = 987654321;

int x, y, d, t, p;

int main() {
  FASTIO;
  cin >> x >> y >> d >> t;
  cout<<fixed; cout.precision(11);
  double dis = sqrt(pow(x, 2) + pow(y, 2)), r;
  int p = (int)dis / d; r = dis - p*d;
  if(p) cout << min({ dis, t * p + r, (double)t * (p - 1) + 2 * t, t * (p + 1) + abs(r - d) });
  else cout << min({ dis, t + abs(d - r), (double)2 * t });
  return 0;
}


short version for fun


1
2
3
4
5
6
7
8
9
10
#include <bits/stdc++.h>
using namespace std;
int x,y,d,p;
double t,D,r;
int main(){
  cin>>x>>y>>d>>t;
  D=sqrt(x*x+y*y),p=D/d,r=D-p*d;
  printf("%.9lf",min({D,t*p+r,max(0.0,t*--p)+2*t,t*++++p+abs(r-d)}));
  return 0;
}
This post is licensed under CC BY 4.0 by the author.