CF1254C.Point Ordering

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an interactive problem.

Khanh has nn points on the Cartesian plane, denoted by a1,a2,…,ana_1, a_2, \ldots, a_n. All points' coordinates are integers between −109-10^9 and 10910^9, inclusive. No three points are collinear. He says that these points are vertices of a convex polygon; in other words, there exists a permutation p1,p2,…,pnp_1, p_2, \ldots, p_n of integers from 11 to nn such that the polygon ap1ap2…apna_{p_1} a_{p_2} \ldots a_{p_n} is convex and vertices are listed in counter-clockwise order.

Khanh gives you the number nn, but hides the coordinates of his points. Your task is to guess the above permutation by asking multiple queries. In each query, you give Khanh 44 integers tt, ii, jj, kk; where either t=1t = 1 or t=2t = 2; and ii, jj, kk are three distinct indices from 11 to nn, inclusive. In response, Khanh tells you:

  • if t=1t = 1, the area of the triangle aiajaka_ia_ja_k multiplied by 22.
  • if t=2t = 2, the sign of the cross product of two vectors aiaj→\overrightarrow{a_ia_j} and aiak→\overrightarrow{a_ia_k}.

Recall that the cross product of vector a→=(xa,ya)\overrightarrow{a} = (x_a, y_a) and vector b→=(xb,yb)\overrightarrow{b} = (x_b, y_b) is the integer xa⋅yb−xb⋅yax_a \cdot y_b - x_b \cdot y_a. The sign of a number is 11 it it is positive, and −1-1 otherwise. It can be proven that the cross product obtained in the above queries can not be 00.

You can ask at most 3⋅n3 \cdot n queries.

Please note that Khanh fixes the coordinates of his points and does not change it while answering your queries. You do not need to guess the coordinates. In your permutation ap1ap2…apna_{p_1}a_{p_2}\ldots a_{p_n}, p1p_1 should be equal to 11 and the indices of vertices should be listed in counter-clockwise order.

Interaction

You start the interaction by reading nn (3≤n≤1 0003 \leq n \leq 1\,000) — the number of vertices.

To ask a query, write 44 integers tt, ii, jj, kk (1≤t≤21 \leq t \leq 2, 1≤i,j,k≤n1 \leq i, j, k \leq n) in a separate line. ii, jj and kk should be distinct.

Then read a single integer to get the answer to this query, as explained above. It can be proven that the answer of a query is always an integer.

When you find the permutation, write a number 00. Then write nn integers p1,p2,…,pnp_1, p_2, \ldots, p_n in the same line.

After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see documentation for other languages.

Hack format

To hack, use the following format:

The first line contains an integer nn (3≤n≤1 0003 \leq n \leq 1\,000) — the number of vertices.

The ii-th of the next nn lines contains two integers xix_i and yiy_i (−109≤xi,yi≤109-10^9 \le x_i, y_i \le 10^9) — the coordinate of the point aia_i.

这是一个交互式问题。

Khanh 在笛卡尔平面上有 nn 个点,记为 a1,a2,…,ana_1, a_2, \ldots, a_n。所有点的坐标均为介于 −109-10^9 与 10910^9(含端点)之间的整数。任意三点不共线。他声称这些点构成一个凸多边形的顶点;换言之,存在 11 到 nn 的一个排列 p1,p2,…,pnp_1, p_2, \ldots, p_n,使得多边形 ap1ap2…apna_{p_1} a_{p_2} \ldots a_{p_n} 是凸的,且顶点按逆时针顺序列出。

Khanh 向你给出数字 nn,但隐藏了各点的坐标。你的任务是通过多次查询来猜出上述排列。每次查询中,你向 Khanh 提供四个整数 tt, ii, jj, kk:其中 t=1t = 1 或 t=2t = 2;ii, jj, kk 是 11 到 nn 中互不相同的下标。Khanh 将返回以下信息:

  • 若 t=1t = 1,则返回三角形 aiajaka_i a_j a_k 面积的两倍;
  • 若 t=2t = 2,则返回向量 aiaj→\overrightarrow{a_i a_j} 与 aiak→\overrightarrow{a_i a_k} 的叉积的符号。

回忆一下:向量 a→=(xa,ya)\overrightarrow{a} = (x_a, y_a) 与向量 b→=(xb,yb)\overrightarrow{b} = (x_b, y_b) 的叉积为整数 xa⋅yb−xb⋅yax_a \cdot y_b - x_b \cdot y_a。一个数的符号定义为:若其为正,则为 11;否则为 −1-1。可以证明:上述查询中得到的叉积不可能为 00。

你最多可进行 3⋅n3 \cdot n 次查询。

请注意,Khanh 在回答你的查询过程中固定各点坐标,不会更改。你无需猜测各点的具体坐标。在你输出的排列 ap1ap2…apna_{p_1}a_{p_2}\ldots a_{p_n} 中,必须满足 p1=1p_1 = 1,且顶点下标需按逆时针顺序列出。

交互方式

首先读入 nn(3≤n≤1 0003 \leq n \leq 1\,000)——即顶点数量。

为进行一次查询,请在单独一行中输出四个整数 tt, ii, jj, kk(1≤t≤21 \leq t \leq 2, 1≤i,j,k≤n1 \leq i, j, k \leq n)。其中 ii, jj, kk 必须互不相同。

然后读入一个整数,即该查询的答案(如上所述)。可以证明:每次查询的答案恒为整数。

当你确定了排列,请先输出一个数字 00,再在同一行中输出 nn 个整数 p1,p2,…,pnp_1, p_2, \ldots, p_n。

每次输出查询后,请务必输出换行符并刷新输出缓冲区;否则将收到“空闲超限”(Idleness limit exceeded)错误。为此,请使用以下方式:

  • C++ 中使用 fflush(stdout) 或 cout.flush();
  • Java 中使用 System.out.flush();
  • Pascal 中使用 flush(output);
  • Python 中使用 stdout.flush();
  • 其他语言请参考相应文档。

Hack 格式

用于 hack 的输入格式如下:

第一行为一个整数 nn(3≤n≤1 0003 \leq n \leq 1\,000)——即顶点数量。

接下来 nn 行中的第 ii 行包含两个整数 xix_i 和 yiy_i(−109≤xi,yi≤109-10^9 \le x_i, y_i \le 10^9)——表示点 aia_i 的坐标。

输入输出样例

  • 输入#1

    6
    
    15
    
    -1
    
    1

    输出#1

    1 1 4 6
    
    2 1 5 6
    
    2 2 1 4
    
    0 1 3 4 2 6 5

说明/提示

The image below shows the hidden polygon in the example:

The interaction in the example goes as below:

  • Contestant reads n=6n = 6.
  • Contestant asks a query with t=1t = 1, i=1i = 1, j=4j = 4, k=6k = 6.
  • Jury answers 1515. The area of the triangle A1A4A6A_1A_4A_6 is 7.57.5. Note that the answer is two times the area of the triangle.
  • Contestant asks a query with t=2t = 2, i=1i = 1, j=5j = 5, k=6k = 6.
  • Jury answers −1-1. The cross product of A1A5→=(2,2)\overrightarrow{A_1A_5} = (2, 2) and A1A6→=(4,1)\overrightarrow{A_1A_6} = (4, 1) is −2-2. The sign of −2-2 is −1-1.
  • Contestant asks a query with t=2t = 2, i=2i = 2, j=1j = 1, k=4k = 4.
  • Jury answers 11. The cross product of A2A1→=(−5,2)\overrightarrow{A_2A_1} = (-5, 2) and A2A4→=(−2,−1)\overrightarrow{A_2A_4} = (-2, -1) is 11. The sign of 11 is 11.
  • Contestant says that the permutation is (1,3,4,2,6,5)(1, 3, 4, 2, 6, 5).

下图展示了示例中的隐藏多边形:

示例中的交互过程如下:

  • 选手读入 n=6n = 6。
  • 选手提出一个查询,其中 t=1t = 1,i=1i = 1,j=4j = 4,k=6k = 6。
  • 评委会回答 1515。三角形 A1A4A6A_1A_4A_6 的面积为 7.57.5。注意:返回值是该三角形面积的两倍。
  • 选手提出一个查询,其中 t=2t = 2,i=1i = 1,j=5j = 5,k=6k = 6。
  • 评委会回答 −1-1。向量 A1A5→=(2,2)\overrightarrow{A_1A_5} = (2, 2) 与 A1A6→=(4,1)\overrightarrow{A_1A_6} = (4, 1) 的叉积为 −2-2,其符号为 −1-1。
  • 选手提出一个查询,其中 t=2t = 2,i=2i = 2,j=1j = 1,k=4k = 4。
  • 评委会回答 11。向量 A2A1→=(−5,2)\overrightarrow{A_2A_1} = (-5, 2) 与 A2A4→=(−2,−1)\overrightarrow{A_2A_4} = (-2, -1) 的叉积为 11,其符号为 11。
  • 选手给出排列 (1,3,4,2,6,5)(1, 3, 4, 2, 6, 5)。

输入解题思路,AI测评打分。不知道怎么写?

首页