A - Dowsing Rod Editorial /

Time Limit: 3 sec / Memory Limit: 1024 MB

問題文

超能力者の高橋くんは宝の地図を発見した。 地図によると、とある無人島の地下に 50 個の埋蔵金が眠っているらしい。 無人島は半径 R=10^9 の円形をしており、残念ながら島のどこに埋蔵金が埋められているかまでは記されていない。 全ての場所を掘り返すことは不可能なので、以下のようにして超能力で埋蔵金を探すことにした。

  1. 好きな場所を選んで木の棒を立てる。
  2. 選んだ場所から半径 D=10^6 以内に埋蔵金がある場合、棒は倒れず直立するので、半径 D の範囲を全て掘ることで埋蔵金が発見できる。
  3. 選んだ場所から半径 D 以内に埋蔵金がない場合、棒は後述する法則に従ってある向きに倒れるため、埋蔵金のありかの手がかりを得ることが出来る。

この操作を最大 1000 回繰り返すことで、出来るだけ多くの埋蔵金を出来るだけ早く発見せよ。

棒の倒れる方向の法則

棒を立てた座標を q=(qx, qy) としたとき、棒の倒れる方向 \theta (0\leq \theta<2\pi) は、入力として与えられる定数 \sigma を用いて、以下のように計算される。

  1. まだ掘り起こされていない埋蔵金の中から、q へのユークリッド距離の二乗に反比例する確率で一つが選ばれる。
  2. 選ばれた埋蔵金の眠る座標を p=(px,py) とし、q から見た p の方角 \hat{\theta}=\mathrm{atan2}(py-qy,px-qx) を計算する。
  3. 平均 \hat{\theta}、標準偏差 \sigma の正規分布から値を一つサンプルし、それを 2\pi で割った余りを \theta とする。

入出力

まずはじめに、標準偏差 \sigma の情報が標準入力から一行で与えられる。 \sigma0.001 の倍数であり、0.001\leq \sigma\leq 0.100 を満たす。

入力を読み込んだら、以下の処理を最大 1000 回繰り返す。 k 回目の処理ではまず、棒を立てる位置 (qx_k, qy_k) を選択し、以下の形式で標準出力に一行で出力せよ。

qx_k qy_k

qx_k, qy_k は整数で、qx_k^2+qy_k^2\leq R^2 を満たさなければならない。範囲外の点を指定した場合はWAとなる。 出力の後には改行をし、更に標準出力を flush しなければならない。 そうしない場合、TLEとなる可能性がある。

次に、立てた棒がどうなったかの情報が、以下のように標準入力から一行で与えられる。

棒が \theta_k の方向に倒れた場合:

0 \theta_k

\theta_k0 以上 2\pi 未満であり、小数点以下 10 桁に丸められて与えられる。

棒が倒れず、座標 (x_k, y_k) にある埋蔵金を発見した場合:

r_k x_k y_k

r_k は発見した埋蔵金が最後の一つの場合は2、そうでない場合は1である。 異なる埋蔵金間の距離は 2D より大きいことが保証されており、同時に複数の埋蔵金を発見することはない。 全ての埋蔵金を発見したら即座にプログラムを終了せよ。 そうしない場合、それ以降のクエリは結果が返って来ないため、TLEREとなる可能性がある。

k Output Input
0
0.051
1
-449800796 341903569
0 4.2119508044
2
-302629026 250885846
0 4.7012310463
3
-132900000 -988000000
1 -132899921 -988157302
\vdots

得点

1000 回以内のクエリで全ての埋蔵金を発見出来なかった場合、発見した埋蔵金の個数を F として、100F の得点が得られる。 Q(\leq 1000) 回のクエリで全ての埋蔵金を発見した場合、10000-5Q の得点が得られる。 全ての埋蔵金を発見しておらず、かつクエリ数が 1000 に満たない場合はWAと判定される。

テストケースは全部で 200 個あり、各テストケースの得点の合計が提出の得点となる。 一つ以上のテストケースで不正な出力や制限時間超過をした場合、提出全体の判定がWATLEとなる。 コンテスト時間中に得た最高得点で最終順位が決定され、コンテスト終了後のシステムテストは行われない。 同じ得点を複数の参加者が得た場合、その得点を獲得した提出の早い方が上位となる。

入力生成方法

L 以上 U 以下の整数値を一様ランダムに生成する関数を \mathrm{rand}(L,U) で表す。 \sigma0.001\times \mathrm{rand}(1,100) により生成される。 50 個の埋蔵金の眠る座標 p_0\cdots,p_{49} は以下のように順に生成される。

  1. i 番目の埋蔵金の座標 p_i=(px_i,py_i)px_i^2+py_i^2\leq R^2 を満たす整数の中から一様ランダムに生成する。
  2. 既に生成した p_j (j<i) の中に、p_i とのユークリッド距離が 2D 以下のものがある間、p_i を選び直す。

ツール(入力ジェネレータ・ビジュアライザ・ローカルテスタ)

コンテスト期間中に、ビジュアライズ結果の共有や、解法・考察に関する言及は禁止されています。ご注意下さい。

ツールで用いられる入出力ファイルの仕様

ローカルテスタに与える入力ファイルは以下の形式を用いている。

\sigma
px_0 py_0
\vdots
px_{49} py_{49}
\mathrm{seed}

最後の \mathrm{seed} は棒の倒れる方向の計算に用いられる乱数シード値である。 棒の倒れる方向は棒を立てた位置に依存するため、入力ファイルには乱数シード値のみが記載されている。

ローカルテスタは解答プログラムの出力をそのまま出力ファイルに書き出す。 解答プログラムは、# から始まるコメント行を出力に含めても良い。 Web版ビジュアライザを使用すると、コメント行を対応するクエリと合わせて表示出来るため、デバッグや考察等に役立てることが出来る。 ジャッジプログラムはコメント行を全て無視するため、コメント行を出力するプログラムをそのまま提出可能である。

コメント行のうち、以下で始まるものはビジュアライザで特別扱いされる。

  • #r: 提供されているローカルテスタを用いない場合にクエリ結果として解答プログラムに与える文字列を #r 0 0.0123456789 のような形式で出力することで、ビジュアライザに情報を伝えることが出来る。提供されているローカルテスタを用いた場合にも自動で挿入される。
  • #c: 以下の形式で出力することで、地点 (x, y) を RGB値が (r,g,b) の色でマーキングする(0\leq r,g,b\leq 255)。埋蔵金のありそうな場所の確認など自由に活用できる。マーキングはターン毎に解除されるので必要があれば毎回出力すること。
#c x y r g b

Problem Statement

A psychic, Takahashi, has discovered a treasure map. According to the map, there are 50 buried treasures under the ground of an uninhabited island. The island has a circular shape with a radius of R=10^9. Unfortunately, the map does not indicate the locations of the buried treasures. Since it is impossible to dig up all the ground, he decided to use his psychic powers to search for the treasures in the following way.

  1. Choose a desired location and stand a wooden rod.
  2. If there is a treasure within a radius of D=10^6 from the chosen location, the rod will remain standing, and he can find the treasure by digging all the area within the radius D.
  3. If there are no treasures within a radius of D from the chosen location, the rod will fall in a certain direction according to the rule described below, providing a clue to the location of the treasures.

By repeating this process up to 1000 times, find as many treasures as possible, as quickly as possible.

The law of the falling direction of the rod

Let q=(qx, qy) be the coordinates at which the rod stands, then the falling direction \theta (0\leq \theta<2\pi) is calculated as follows, using a constant \sigma given as an input.

  1. Among the treasures that have not yet been dug up, one is chosen with probability proportional to the inverse of the squared Euclidean distance to q.
  2. Let p=(px,py) be the coordinates of the chosen treasure, and calculate the direction \hat{\theta}=\mathrm{atan2}(py-qy,px-qx) of p-q.
  3. Sample a value from Gaussian distribution with mean \hat{\theta} and standard deviation \sigma and let \theta be its remainder divided by 2\pi.

Input and Output

First, the standard deviation \sigma is given in a single line from Standard Input. \sigma is a multiple of 0.001 and satisfies 0.001\leq \sigma\leq 0.100.

After reading the input, repeat the following process up to 1000 times. In the k-th process, first choose the location (qx_k, qy_k) to stand the rod, and output a single line to Standard Output in the following format.

qx_k qy_k

qx_k and qy_k must be integers satisfying qx_k^2+qy_k^2\leq R^2. If you specify a point outside the range, you will get WA. The output must be followed by a new line, and you have to flush Standard Output. Otherwise, the submission might be judged as TLE.

Then, the information about what happened to the rod is given in a single line from Standard Input as follows.

If the rod falls in the direction of \theta_k:

0 \theta_k

\theta_k is between 0 and 2\pi and is given rounded to 10 decimal places.

If the rod remains standing and you find a treasure at the coordinates (x_k,y_k):

r_k x_k y_k

r_k is 2 if the found treasure is the last one, and 1 otherwise. The distance between different treasures is guaranteed to be greater than 2D, so you will not find more than one treasure simultaneously. When you have found all the treasures, you must immediately terminate the program. Otherwise, any subsequent queries will not return a response so the submission might be judged as TLE or RE.

Example

k Output Input
0
0.051
1
-449800796 341903569
0 4.2119508044
2
-302629026 250885846
0 4.7012310463
3
-132900000 -988000000
1 -132899921 -988157302
\vdots

Scoring

If you failed to find all the treasures within 1000 queries, the score for the test case is 100F, where F is the number of treasures you found. If you found all the treasures in Q(\leq 1000) queries, the score for the test case is 10000-5Q. If you have not found all the treasures and the number of queries is less than 1000, the submission will be judged as WA.

There are 200 test cases, and the score of a submission is the total score for each test case. If you get a result other than AC for one or more test cases, the score of the submission will be zero. The highest score obtained during the contest time will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, the ranking will be determined by the submission time of the submission that received that score.

Input Generation

Let \mathrm{rand}(L,U) be a function that generates a uniform random integer between L and U, inclusive. \sigma is generated by 0.001\times \mathrm{rand}(1,100). The coordinates p_0\cdots,p_{49} of 50 buried treasures are generated as follows.

  1. Generate the coordinates p_i=(px_i,py_i) of the i-th buried treasure uniformly at random among integers satisfying px_i^2+py_i^2\leq R^2.
  2. While there is an already generated p_j (j<i) whose Euclidean distance from p_i is less than or equal to 2D, re-generate p_i.

Tools (Input generator, visualizer, and local tester)

Please be aware that sharing visualization results or discussing solutions/ideas during the contest is prohibited.

Specification of input/output files used by the tools

Input files given to the local tester have the following format.

\sigma
px_0 py_0
\vdots
px_{49} py_{49}
\mathrm{seed}

The last \mathrm{seed} is a random seed value used to generate the fallen directions. Since directions depend on the rod's locations, the input file contains only the random seed value.

The local tester writes outputs from your program directly to the output file. Your program may output comment lines starting with #. The visualizer displays the comment lines with the corresponding query, which may be useful for debugging and analysis. Since the judge program ignores all comment lines, you can submit a program that outputs comment lines as is.

Comment lines that begin with the following have special meaning in the visualizer.

  • #r: When you do not use the provided local tester, by outputting a response string given to the solution program in the form of #r 0 0.0123456789, you can provide the information to the visualizer. The provided local tester also automatically inserts these comment lines.
  • #c: By outputting in the following format, you can mark a point (x, y) with RGB color (r,g,b) (0\leq r,g,b\leq 255). You can utilize this function, for example, to check the possible location of a buried treasure. The marking is removed at each turn, so if necessary, output it every turn.
#c x y r g b