QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#14946. 衝突ダメージ

Statistics

2D 物理演算ベースのビデオゲームにおいて、2 人のキャラクター $P$ と $Q$ が戦場を移動しています。各キャラクターは当たり判定(コリジョンボックス)として機能する凸多角形で表されます。2 つの当たり判定が重なると、ゲームはそれらの共通部分の面積を衝突ダメージとして計算します。

しかし、アリーナ内の予測不可能な気流により、キャラクター $Q$ は任意の平行移動ベクトル $\mathbf{t} = (t_x, t_y)$ によって変位しますが、回転や反転はしません。$Q$ が実際に $P$ と衝突するように(すなわち、それらの共通部分が正の面積を持つように)一様かつランダムに配置されたときの、衝突ダメージの期待値を計算してください。

より形式的には、キャラクター $P$ を表す多角形と、ベクトル $\mathbf{t}$ に沿って平行移動した後のキャラクター $Q$ を表す多角形との共通部分の面積を $f(\mathbf{t})$ と定義します。$f(\mathbf{t}) > 0$ となるすべての平行移動ベクトル $\mathbf{t}$ の集合を $D \subseteq \mathbb{R}^2$ とします。$D$ は正の面積を持つことが示せ、これを $|D|$ と表します。$\frac{1}{|D|} \iint_D f(\mathbf{t})\,d\mathbf{t}$ を計算してください。

入力

入力の 1 行目には、テストケースの数を表す整数 $T$($1 \le T \le 300$)が与えられます。各テストケースについて:

  • 1 行目には、2 つの凸多角形の頂点数をそれぞれ表す 2 つの整数 $n$ と $m$($3 \le n, m \le 1\,000$)が与えられます。
  • 続く $n$ 行には、それぞれ 2 つの整数 $x$ と $y$($-10^4 \le x, y \le 10^4$)が与えられ、キャラクター $P$ を表す多角形の頂点座標 $(x, y)$ を表します。
  • さらに続く $m$ 行には、それぞれ 2 つの整数 $x$ と $y$($-10^4 \le x, y \le 10^4$)が与えられ、キャラクター $Q$ を表す多角形の頂点座標 $(x, y)$ を表します。
  • 凸多角形の頂点は反時計回りの順序で与えられ、どの 3 頂点も同一直線上にないことが保証されます。

すべてのテストケースにおける $n$ の総和および $m$ の総和は、いずれも $1\,000$ を超えないことが保証されます。

出力

各テストケースについて、衝突ダメージの期待値を表す実数を 1 行に出力してください。

出力の絶対誤差または相対誤差が $10^{-6}$ 以下であれば正解とみなされます。形式的には、あなたの出力を $a$、ジャッジの解を $b$ としたとき、$\frac{|a - b|}{\max(1, |b|)} \le 10^{-6}$ を満たす場合に限り出力が受理されます。

入出力例

入力 1

2
3 3
0 0
1 0
0 1
0 0
1 0
0 1
3 3
0 0
1 0
0 1
0 1
1 0
1 1

出力 1

0.083333333333
0.125000000000

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.