多校训练第1轮.F——Final Spark【计算几何】

题目传送门


题目描述

Lux has a plan to eliminate the invisible motionless enemy Teemo, whose location is detected by the Oracle Lens. She decides to cast an ultimate skill immediately, which would slay Teemo if hit because Lux has very high ability power.

Lux’s ultimate skill, Final Spark, is a powerful skill which can damage enemies by a straight beam of light with infinite length and ww meters width. It will deal damage to who shares at least a point with the light beam.
在这里插入图片描述
But Teemo - The Swift Scout - is a well-trained soldier. He will fleetly react to the Lux’s action, and try to dodge the ray by choosing a uniformly random direction and run along the direction. Between the first action of Lux and the moment the ray finally pokes out, Lux needs time to channel the ultimate, and during the channelling Teemo can run ss meters - note that Teemo always run in a straight line.

She should choose the direction of the Final Spark before any action is taken. At the instant before Lux casting the ultimate skill using the best strategy, she wonders how possible is the skill hit Teemo. She recalls that Teemo can be recognized as a circle with radius rr meters, and now Teemo is dd meters away from Lux.

It’s very hard for Lux to calculate it. Can you answer Lux the possibility of hitting Teemo when she uses the best strategy?


输入格式

The first line contains an integer T ( 1 T 1 0 5 ) T(1 \leq T \leq 10 ^ 5) - the number of test cases.

Each test case description contains the only line with four integers, w , t , s , d ( 0 w , r , s 1000 , 1 d 3000 ) w,t,s,d (0 \leq w, r, s \leq 1000, 1 \leq d \leq 3000) - the width of light beam, diameter of Teemo, the distance Teemo can run during Lux channelling her Final Spark, the distance between Lux and Teemo.

It is guaranteed that w + t + s < d w+t+s<d , so Teemo can not run through Lux, and the start of the light beam can not touch Teemo.


输出格式

For each test case, print a single number denoting the maximum possiblity on a separate line. The absolute error should not exceed 1 0 6 10 ^ {-6} .

Formally, let your answer be A A , and the jury’s answer be B B . Your answer is accepted if and only if A B 1 0 6 |A-B| \leq 10 ^ {-6}


输入

3
20 20 20 1000
0 0 100 1000
100 100 198 2000


输出 #1复制

1.000000000
0.000000000
0.503215306


说明/提示

In the first case of the example, Lux will shoot along the direction exactly through the center of Teemo. Teemo is unable to escape.

In the second case of the example, wherever Lux shoot, the possibility is 0 0 because the possible position of Teemo forms a circle with radius 100 100 , but the width of the ray and the diameter of Teemo are both 0 0 .


题意

  • 拉克丝在距离提莫 d d 处,向提莫释放大招
  • 提莫在拉克丝抬手的时候可以任意一个方向移动 s s 远(直线)
  • 提莫视为半径为 r r 的圆,拉克丝大招范围宽度为 w w
  • 求命中提莫的概率
  • 注意:由于出题人考虑不周,输入的不是提莫的半径r,而是提莫的直径t

题解

  • w + t w + t 相同的数据都没有本质区别,因此可以转化为 r = 0 , w = w + t r′ = 0, w′ = w + t 的题目来做。无论以什么角
    度射入圆,我们都可以把圆旋转到激光为竖直的情况来开,因此问题就转化为用一个可水平平移的无限
    w + t w + t 宽的长方形切一个半径为 s s 的圆能切下的最大边长。求导可知相切时边长取最大值,因此计算
    相应弧长即可。
  • 三分大师也许能通过这道题,但是太麻烦了,而且还可能被卡。
  • 如图为原始问题
    在这里插入图片描述
  • 转变为下图问题在这里插入图片描述

AC-Code

#include <bits/stdc++.h>
using namespace std;

int main() {
	int T;	cin >> T;	while (T--) {
		double w, r, s, d;	cin >> w >> r >> s >> d;
		w += r;
		if (w >= 2 * s) { cout << "1.000000000" << endl;	continue; }
		else if (w <= 0) { cout << "0.000000000" << endl;	continue; }
		else {
			double a = s - w;
			double theta = acos(a / s);
			cout << setprecision(9) << theta / acos(-1) << endl;
		}
	}
	return 0;
}
发布了212 篇原创文章 · 获赞 148 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Q_1849805767/article/details/104626514