CF1847E.Triangle Platinum?
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is an interactive problem.
Made in Heaven is a rather curious Stand. Of course, it is (arguably) the strongest Stand in existence, but it is also an ardent puzzle enjoyer. For example, it gave Qtaro the following problem recently:
Made in Heaven has n hidden integers a1,a2,…,an (3≤n≤5000, 1≤ai≤4). Qtaro must determine all the ai by asking Made in Heaven some queries of the following form:
- In one query Qtaro is allowed to give Made in Heaven three distinct indexes i, j and k (1≤i,j,k≤n).
- If ai,aj,ak form the sides of a non-degenerate triangle†, Made in Heaven will respond with the area of this triangle.
- Otherwise, Made in Heaven will respond with 0.
By asking at most 5500 such questions, Qtaro must either tell Made in Heaven all the values of the ai, or report that it is not possible to uniquely determine them.
Unfortunately due to the universe reboot, Qtaro is not as smart as Jotaro. Please help Qtaro solve Made In Heaven's problem.
——————————————————————
† Three positive integers a,b,c are said to form the sides of a non-degenerate triangle if and only if all of the following three inequalities hold:
- a+b>c,
- b+c>a,
- c+a>b.
Interaction
The interaction begins with reading n (3≤n≤5000), the number of hidden integers.
To ask a question corresponding to the triple (i,j,k) (1≤i<j<k≤n), output "? i j k" without quotes. Afterward, you should read a single integer s.
- If s=0, then ai, aj, and ak are not the sides of a non-degenerate triangle.
- Otherwise, s=16Δ2, where Δ is the area of the triangle. The area is provided in this format for your convenience so that you need only take integer input.
If the numbers ai cannot be uniquely determined print "! −1" without quotes. On the other hand, if you have determined all the values of ai print "! a1 a2 … an" on a single line.
The interactor is non-adaptive. The hidden array a1,a2,…,an is fixed beforehand and is not changed during the interaction process.
After printing a query do not forget to output the 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 the documentation for other languages.
Hacks
You can hack a solution with the following input format.
The first line contains a single integer n (3≤n≤5000) — the number of hidden integers.
The second line contains n integers a1,a2,…,an (1≤ai≤4) — the hidden array.
这是一个交互式问题。
“天堂制造”是一种相当奇特的替身。当然,它( arguably )是现存最强的替身,但它同时也是一位热衷解谜的爱好者。例如,它最近向 Qtaro 提出了如下问题:
“天堂制造”隐藏了 n 个整数 a1,a2,…,an(其中 3≤n≤5000,且 1≤ai≤4)。Qtaro 必须通过向“天堂制造”提出若干查询来确定所有 ai 的值。每次查询的形式如下:
- 在一次查询中,Qtaro 可向“天堂制造”提供三个互不相同的下标 i、j 和 k(满足 1≤i,j,k≤n);
- 若 ai,aj,ak 能构成一个非退化三角形†,“天堂制造”将返回该三角形的面积;
- 否则,“天堂制造”将返回 0。
Qtaro 至多可提出 5500 次此类查询,之后必须要么向“天堂制造”报告全部 ai 的值,要么声明这些值无法被唯一确定。
不幸的是,由于宇宙重启,Qtaro 不再像乔鲁诺那般聪慧。请帮助 Qtaro 解决“天堂制造”的难题。
——————————————————————
† 三个正整数 a,b,c 被称为能构成一个非退化三角形,当且仅当以下三个不等式同时成立:
- a+b>c,
- b+c>a,
- c+a>b。
交互方式
交互开始时,首先读入整数 n(3≤n≤5000),即隐藏整数的个数。
要对三元组 (i,j,k)(其中 1≤i<j<k≤n)发起一次查询,请输出 ? i j k(不含引号)。随后,你需要读入一个整数 s:
- 若 s=0,表示 ai、aj 和 ak 不能构成非退化三角形;
- 否则,s=16Δ2,其中 Δ 是该三角形的面积。为便于处理,面积以这种形式给出,因此你只需读取整数即可。
若无法唯一确定数组 ai,请输出 ! -1(不含引号);
若已完全确定所有 ai 的值,请在一行内输出 ! a_1 a_2 ... a_n。
该交互器为非自适应型:隐藏数组 a1,a2,…,an 在交互开始前即已固定,且在整个交互过程中不会改变。
每次输出查询后,请务必输出换行符并刷新输出缓冲区;否则你将收到 “Idleness limit exceeded” 错误。为此,请使用以下方式:
- C++ 中:
fflush(stdout)或cout.flush(); - Java 中:
System.out.flush(); - Pascal 中:
flush(output); - Python 中:
stdout.flush(); - 其他语言请参阅相应文档。
Hack(数据构造)
你可以按如下格式构造 Hack 数据:
第一行包含一个整数 n(3≤n≤5000)—— 隐藏整数的个数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤4)—— 隐藏数组。
输入输出样例
输入#1
3 63
输出#1
? 1 2 3 ! -1
输入#2
6 0 0 0 63 15 135
输出#2
? 1 2 3 ? 2 3 4 ? 4 5 6 ? 1 5 6 ? 3 5 6 ? 1 2 4 ! 3 2 1 4 2 2
输入#3
15 3 3 3 3 3 0
输出#3
? 1 2 3 ? 4 6 7 ? 8 9 10 ? 11 12 13 ? 13 14 15 ? 4 5 6 ! -1
输入#4
15 3 15 0 3 3 3
输出#4
? 1 2 3 ? 3 4 5 ? 4 5 6 ? 7 8 9 ? 10 11 12 ? 13 14 15 ! 1 1 1 2 2 4 1 1 1 1 1 1 1 1 1 1
输入#5
10 3 48 3 48 63 0
输出#5
? 1 3 5 ? 4 6 8 ? 1 5 9 ? 6 8 10 ? 4 2 6 ? 7 10 8 ! 1 3 1 2 1 2 4 2 1 2
说明/提示
In the first example, the interaction process happens as follows:
Stdin
Stdout
Explanation
3
Read n=3. There are 3 hidden integers
? 1 2 3
Ask for the area formed by a1, a2 and a3
63
Received 16Δ2=63. So the area Δ=1663≈1.984313
! -1
Answer that there is no unique array satisfying the queries.
From the area received, we can deduce that the numbers that forms the triangle are either (4, 4, 1) or (3, 2, 2) (in some order). As there are multiple arrays of numbers that satisfy the queries, a unique answer cannot be found.
In the second example, the interaction process happens as follows:
Step
Stdin
Stdout
Explanation
1
6
Read n=6. There are 6 hidden integers
2
? 1 2 3
Ask for the area formed by a1, a2 and a3
3
0
Does not form a non-degenerate triangle
4
? 2 3 4
Ask for the area formed by a2, a3 and a4
5
0
Does not form a non-degenerate triangle
6
? 4 5 6
Ask for the area formed by a4, a5 and a6
7
0
Does not form a non-degenerate triangle
8
? 1 5 6
Ask for the area formed by a1, a5 and a6
9
63
Received 16Δ2=63. So the area Δ=1663≈1.984313
10
? 3 5 6
Ask for the area formed by a3, a5 and a6
11
15
Received 16Δ2=15. So the area Δ=1615≈0.968245
12
? 1 2 4
Ask for the area formed by a3, a5 and a6
13
135
Received 16Δ2=135. So the area Δ=16135≈2.904738
14
! 3 2 1 4 2 2
A unique answer is found, which is a=[3,2,1,4,2,2].
From steps 10 and 11, we can deduce that the the multiset \left{a_3, a_5, a_6\right} must be \left{2, 2, 1\right}.
From steps 8 and 9, the multiset \left{a_1, a_5, a_6\right} must be either \left{4, 4, 1\right} or \left{3, 2, 2\right}.
As \left{a_3, a_5, a_6\right} and \left{a_1, a_5, a_6\right} share a5 and a6, we conclude that a5=a6=2, as well as a1=3, a3=1.
From steps 6 and 7, we know that a5=a6=2, and a4, a5 and a6 cannot form a non-degenerate triangle, hence a4=4.
With all the known information, only a2=2 satisfies the queries made in steps 2, 3, 4, 5, 12 and 13.
In the third example, one array that satisfies the queries is [1,1,1,1,3,1,1,1,1,1,1,1,1,1,1].
在第一个例子中,交互过程如下所示:
标准输入(Stdin)
标准输出(Stdout)
说明(Explanation)
3
读入 n=3。共有 3 个隐藏整数。
? 1 2 3
询问由 a1、a2 和 a3 构成的三角形的面积。
63
收到 16Δ2=63。因此面积 Δ=1663≈1.984313。
! -1
回答:不存在满足所有查询的唯一数组。
由所接收的面积值可推断,构成该三角形的三个数要么是 (4,4,1),要么是 (3,2,2)(顺序任意)。由于存在多个满足查询条件的数组,因此无法确定唯一解。
在第二个例子中,交互过程如下所示:
步骤(Step)
标准输入(Stdin)
标准输出(Stdout)
说明(Explanation)
1
6
读入 n=6。共有 6 个隐藏整数。
2
? 1 2 3
询问由 a1、a2 和 a3 构成的三角形的面积。
3
0
无法构成非退化三角形。
4
? 2 3 4
询问由 a2、a3 和 a4 构成的三角形的面积。
5
0
无法构成非退化三角形。
6
? 4 5 6
询问由 a4、a5 和 a6 构成的三角形的面积。
7
0
无法构成非退化三角形。
8
? 1 5 6
询问由 a1、a5 和 a6 构成的三角形的面积。
9
63
收到 16Δ2=63。因此面积 Δ=1663≈1.984313。
10
? 3 5 6
询问由 a3、a5 和 a6 构成的三角形的面积。
11
15
收到 16Δ2=15。因此面积 Δ=1615≈0.968245。
12
? 1 2 4
询问由 a1、a2 和 a4 构成的三角形的面积。
13
135
收到 16Δ2=135。因此面积 Δ=16135≈2.904738。
14
! 3 2 1 4 2 2
找到了唯一解:a=[3,2,1,4,2,2]。
由步骤 10 和 11 可推断,多重集 {a3,a5,a6} 必为 {2,2,1}。
由步骤 8 和 9 可知,多重集 {a1,a5,a6} 要么是 {4,4,1},要么是 {3,2,2}。
由于 {a3,a5,a6} 与 {a1,a5,a6} 共享 a5 和 a6,因此可得 a5=a6=2,且 a1=3,a3=1。
由步骤 6 和 7 可知 a5=a6=2,而 a4、a5、a6 无法构成非退化三角形,故 a4=4。
结合所有已知信息,仅当 a2=2 时,步骤 2、3、4、5、12 和 13 中的所有查询才得以满足。
在第三个例子中,一个满足所有查询的数组是 [1,1,1,1,3,1,1,1,1,1,1,1,1,1,1]。
输入解题思路,AI测评打分。不知道怎么写?