출처: BOJ Scorched Earth
SOL)
v = v0 + at --- (1)
s = v0t + (1/2)*at^2 --- (2)
위의 2개의 공식으로 푼다.
v의 속력으로 각도 θ로 쏘아 올렸을 때
x축 속력은 v*cosθ y축 속력은 v*sinθ
(2)를 이용해서 t를 얻고 t를 가지고 (1)에 대입하여
답을 구한다.
소스코드를 보면 t를 구하는 공식에 분모가 0이될 가능성이
있게 보이지만 w = 2.0, d = 78.46537---
이런식으로 인풋이 들어와야지 가능하다.
(이런 인풋은 들어오지 않으니 무시해도 된다.)
#include <stdio.h>
#include <math.h>
using namespace std;
const double g = -9.8;
const double pi = acos(-1.0);
int main() {
freopen("input.txt", "r", stdin);
int T; scanf("%d", &T);
while (T--) {
double xu, yu, xo, yo, w, d;
scanf("%lf %lf %lf %lf %lf %lf", &xu, &yu, &xo, &yo, &w, &d);
d = d * pi / 180.0;
double t = sqrt(2.0 * ((xo-xu)*tan(d)-(yo-yu)) / (w*tan(d)-g));
double v = (-.5*w*t*t + xo-xu) / (cos(d)*t);
if (0 <= v && v <= 300) printf("%.5lf\n", v);
else printf("impossible\n");
}
}
#include <math.h>
using namespace std;
const double g = -9.8;
const double pi = acos(-1.0);
int main() {
freopen("input.txt", "r", stdin);
int T; scanf("%d", &T);
while (T--) {
double xu, yu, xo, yo, w, d;
scanf("%lf %lf %lf %lf %lf %lf", &xu, &yu, &xo, &yo, &w, &d);
d = d * pi / 180.0;
double t = sqrt(2.0 * ((xo-xu)*tan(d)-(yo-yu)) / (w*tan(d)-g));
double v = (-.5*w*t*t + xo-xu) / (cos(d)*t);
if (0 <= v && v <= 300) printf("%.5lf\n", v);
else printf("impossible\n");
}
}
댓글 없음:
댓글 쓰기