2015년 11월 21일 토요일

B. Chip 'n Dale Rescue Rangers

Math, Binary Search


출처: Codeforces B. Chip 'n Dale Rescue Rangers

sol)
주석


cpp to html [-] Collapse
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
double a,b,c,d,v,t,e,f,g,h,l=0,r=1e9,m,p,q;
int main()
{
    freopen("input.txt", "r", stdin);
    double x1, y1, x2, y2, v, t, vx, vy, wx, wy;
    cin >> x1 >> y1 >> x2 >> y2 >> v >> t >> vx >> vy >> wx >> wy;
    double L = 0.0, R = 1e9;
    for (int i = 0; i < 1000; i++) {
        double m = (L + R)/2;
        double x = x1 + min(m, t) * vx + max(m - t, 0.0) * wx; //순수 바람으로 가는거리
        double y = y1 + min(m, t) * vy + max(m - t, 0.0) * wy; //순수 바람으로 가는거리
        (hypot(x - x2, y - y2) < v * m ? R : L) = m;
        //바람이 이만큼 방행했는데 사실 더 갈 수 있다.
        //바람만으로 이동했을때 x, y좌표와 목적지 좌표길이 보다
        //v*m으로 가는 거리가 더 크다면 m시간에 갈수 있다는 말이다.
    }
    printf("%.20lf",R);
    return 0;
}

댓글 없음:

댓글 쓰기