QOJ.ac

QOJ

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

#14725. 投影

Statistics

給定一個 $n$ 維超球體與超長方體,定義如下:

超球體:$B \triangleq \{\mathbf{x} \mid \sum_{i=1}^n x_i^2 \le R^2; \mathbf{x} \in \mathbb{R}^n\}$;

超長方體:$C \triangleq \{\mathbf{x} \mid |x_i| \le l_i, \forall i \in [1, n]; \mathbf{x} \in \mathbb{R}^n\}$。

設 $S \triangleq B \cap C$。給定一個點 $\mathbf{x} = (x_1, x_2, \dots, x_n)$,求在 $S$(包含邊界)中距離 $\mathbf{x}$ 最近的點,記為 $\mathbf{y} = (y_1, y_2, \dots, y_n)$。

當且僅當 $\sum_{i=1}^n (x_i - p_i)^2 \le \sum_{i=1}^n (x_i - q_i)^2$ 時,才認為點 $\mathbf{p}$ 比點 $\mathbf{q}$ 更接近 $\mathbf{x}$。

輸入格式

每個測試檔案包含多組測試資料。第一行包含測試資料的組數 $T$ ($1 \le T \le 3 \times 10^4$)。接下來是各組測試資料的描述。

每組測試資料的第一行包含兩個整數 $n$ 與 $a$ ($2 \le n \le 10^5$,$1 \le a \le 10^9$),其中 $a$ 是 $R^2$ 的值。

第二行包含 $n$ 個整數 $x_1, x_2, \dots, x_n$ ($|x_i| \le 10^9$)。

第三行包含 $n$ 個整數 $l_1, l_2, \dots, l_n$ ($1 \le l_i \le 100$)。

對於每個測試檔案,保證所有測試資料中 $n$ 的總和不超過 $10^5$。

輸出格式

對於每組測試資料,輸出一行,包含 $n$ 個實數 $y_1, y_2, \dots, y_n$。

若你的答案的絕對誤差或相對誤差不超過 $10^{-6}$,則視為正確。

形式化地說,設你的答案為 $y_i$,裁判的答案為 $y_i^*$。當且僅當對於所有 $i \in [1, n]$ 皆滿足 $\frac{|y_i - y_i^*|}{\max(1, |y_i^*|)} \le 10^{-6}$ 時,你的答案才會被接受。

範例

輸入範例 1

3
2 25
1 10
4 4
2 25
10 1
4 4
3 6
3 3 3
2 2 2

輸出範例 1

1.0000000000 4.0000000000
4.0000000000 1.0000000000
1.4142135624 1.4142135624 1.4142135624

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.