题目收集
题目列表题单
返回列表

Convex

CodeforcesP0021· ZJU Summer 2026 Contest 2原题链接
交互计算几何

创建于 2026/07/16 · 更新于 2026/07/16

题目描述

This is an interactive problem.

There is a hidden strictly convex polygon PPP. The polygon PPP has exactly nnn vertices. All vertices are integer points, and each vertex (x,y)(x,y)(x,y) satisfies ∣x∣≤106|x| \le 10^6∣x∣≤106 and ∣y∣≤106|y| \le 10^6∣y∣≤106.

You may ask the interactor an integer vector (a,b)(a,b)(a,b). The interactor will return the integer value max⁡p∈P(apx+bpy)\max_{p \in P} (a p_x + b p_y)maxp∈P​(apx​+bpy​), where p=(px,py)p=(p_x,p_y)p=(px​,py​) is any point inside or on the boundary of polygon PPP.

Your task is to determine all vertices of polygon PPP using no more than 3n3n3n queries.

输入格式

First, read an integer TTT (1≤T≤1001 \le T \le 1001≤T≤100), denoting the number of test cases.

For each test case, first read an integer nnn (3≤n≤5003 \le n \le 5003≤n≤500), denoting the number of vertices of the hidden polygon.

It is guaranteed that the sum of nnn over all test cases does not exceed 500500500.

Also, it is guaranteed that the interactor is non-adaptive, which means the polygon is determined before interaction.

输出格式

To ask a query with vector (a,b)(a,b)(a,b) (−109≤a≤109-10^9 \le a \le 10^9−109≤a≤109, −109≤b≤109-10^9 \le b \le 10^9−109≤b≤109, and (a,b)≠(0,0)(a,b) \ne (0,0)(a,b)=(0,0)), output:

? a b? \space a \space b? a b

Then you should read an integer sss, where s=max⁡p∈P(apx+bpy)s=\max_{p \in P} (a p_x + b p_y)s=maxp∈P​(apx​+bpy​).

When you have determined all vertices of polygon PPP for the current test case, output:

! x1 y1 x2 y2…xn yn! \space x_1 \space y_1\space x_2 \space y_2 \dots x_n \space y_n! x1​ y1​ x2​ y2​…xn​ yn​

Here, (xi,yi)(x_i,y_i)(xi​,yi​) (∣xi∣≤106|x_i| \le 10^6∣xi​∣≤106, ∣yi∣≤106|y_i| \le 10^6∣yi​∣≤106) are all vertices of polygon PPP. You may output the vertices in any order.

After outputting the answer, you should continue to the next test case.

样例输入 #1

1
3

19

20

0

30

20

样例输出 #1

? 4 5

? -1 7

? -2 -9

? 0 10

? 5 -1

! 0 0 4 0 1 3