📄 toxophily.cpp
字号:
/**********************************************************************
Author: WHU_dzs
Created Time: 2009-2-15 15:19:13
File Name: pro3.cpp
Description:
**********************************************************************/
#include <iostream>
#include <cmath>
using namespace std;
double x, y, v;
const double g = 9.8;
const double eps = 1E-9;
const double pi = acos(-1.0);
double calc (double theta) {
return x * tan(theta) - (g * x * x) / (2 * v * v * cos(theta) * cos(theta));
}
int main () {
int ca;
scanf("%d", &ca);
while (ca--) {
scanf ("%lf %lf %lf", &x, &y, &v);
double low = 0.0, high = pi / 2;
while (high - low > eps) {
double mid0 = low + (high - low) / 3;
double mid1 = high - (high - low) / 3;
if (calc(mid0) > calc(mid1))
high = mid1;
else
low = mid0;
}
double max_theta = low;
double max_y = calc(max_theta);
if (max_y < y)
printf ("-1\n");
else if (fabs(max_y - y) < eps)
printf ("%.6lf\n", max_theta);
else {
low = 0.0, high = max_theta;
while (high - low > eps) {
double mid = (high + low) / 2;
if (calc(mid) > y)
high = mid;
else
low = mid;
}
double ans1 = low;
low = max_theta, high = pi / 2;
while (high - low > eps) {
double mid = (high + low) / 2;
if (calc(mid) < y)
high = mid;
else
low = mid;
}
double ans2 = low;
printf ("%.6lf\n", min(ans1, ans2));
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -