AT_arc220_d.Long Trail

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a positive integer NN.

Let GG be a complete undirected graph with NN vertices 1,2,…,N1,2,\ldots,N and N(N−1)2\displaystyle \frac{N(N-1)}2 edges.

Find a trail (v1,v2,…,vk)(v_1,v_2,\ldots,v_k) on GG satisfying all of the following conditions.

  • for all integers ii such that 1≤i≤k−21 \leq i \leq k-2, ∣vi−vi+2∣=1|v_i - v_{i+2}| = 1
  • (N−2)22≤k\displaystyle \frac{(N-2)^2}2 \le k

It can be proved that such a trail always exists under the constraints.

What is a trail? A sequence of vertices (v1,v2,…,vk)(v_1,v_2,\ldots,v_k) on an undirected graph GG is called a trail on GG if all of the following conditions are satisfied.

  • 1≤vi≤N.1\le v_i\le N.
  • For 1≤i≤k−11\le i\le k-1, there exists an edge connecting vertices viv_i and vi+1v_{i+1}.
  • For 1≤i<j≤k−11\le i < j \le k-1, the edge connecting vertices viv_i and vi+1v_{i+1} and the edge connecting vertices vjv_j and vj+1v_{j+1} are distinct.

给定一个正整数 NN。

令 GG 是一个具有 NN 个顶点 1,2,…,N1,2,\ldots,N 的无向完全图,共有 N(N−1)2\displaystyle \frac{N(N-1)}{2} 条边。

请在 GG 上找出一条满足以下所有条件的迹(trail)(v1,v2,…,vk)(v_1,v_2,\ldots,v_k):

  • 对所有满足 1≤i≤k−21 \leq i \leq k-2 的整数 ii,均有 ∣vi−vi+2∣=1|v_i - v_{i+2}| = 1;
  • (N−2)22≤k\displaystyle \frac{(N-2)^2}{2} \le k。

在本题约束下,可以证明这样的迹总是存在的。

什么是迹(trail)?在无向图 GG 上,一个顶点序列 (v1,v2,…,vk)(v_1,v_2,\ldots,v_k) 被称为 GG 上的一条迹,当且仅当满足以下所有条件:

  • 1≤vi≤N1\le v_i\le N;
  • 对所有 1≤i≤k−11\le i\le k-1,顶点 viv_i 与 vi+1v_{i+1} 之间存在一条边;
  • 对所有 1≤i<j≤k−11\le i < j \le k-1,连接顶点 viv_i 与 vi+1v_{i+1} 的边和连接顶点 vjv_j 与 vj+1v_{j+1} 的边互不相同。

输入格式

The input is given from Standard Input in the following format:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

Each test case is given in the following format:

NN

输入从标准输入中以如下格式给出:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

每个测试用例以如下格式给出:

NN

输出格式

Output the answers for the test cases in order, separated by newlines.

For each test case, output a trail (v1,v2,…,vk)(v_1,v_2,\ldots,v_k) on GG satisfying all conditions in the following format:

kk
v1v_1 v2v_2 …\ldots vkv_k

If multiple trails on GG satisfying all conditions exist, any of them will be accepted.

按测试用例的顺序输出答案,各答案之间用换行符分隔。

对于每个测试用例,输出图 GG 上一条满足所有条件的迹 (v1,v2,…,vk)(v_1,v_2,\ldots,v_k),格式如下:

kk
v1v_1 v2v_2 …\ldots vkv_k

若存在多条满足所有条件的图 GG 上的迹,则输出任意一条均可。

输入输出样例

  • 输入#1

    2
    3
    5

    输出#1

    3
    1 3 2
    5
    2 1 3 2 4 4
    2 3 1 2

说明/提示

Sample 1 Explanation:
Consider the first test case.

For (v1,v2,v3)=(1,3,2)(v_1,v_2,v_3)=(1,3,2),

  • ∣v1−v3∣=∣1−2∣=1|v_1-v_3|=|1-2|=1
  • (N−2)22=12≤3\displaystyle \frac{(N-2)^2}2=\frac12\le 3
  • The edge connecting vertices 11 and 33 and the edge connecting vertices 33 and 22 are distinct.

Thus, we can confirm that the sample output is a trail satisfying all conditions.

The following output, for example, is also accepted:

Constraints

  • 1≤T≤501\le T\le 50
  • 3≤N≤10003\le N\le 1000
  • The sum of NN over all test cases is at most 10001000.
  • All input values are integers.

样例 1 解释:
考虑第一个测试用例。

对于 (v1,v2,v3)=(1,3,2)(v_1,v_2,v_3)=(1,3,2),

  • ∣v1−v3∣=∣1−2∣=1|v_1-v_3|=|1-2|=1
  • (N−2)22=12≤3\displaystyle \frac{(N-2)^2}2=\frac12\le 3
  • 连接顶点 11 与 33 的边和连接顶点 33 与 22 的边是不同的边。

因此,我们可以确认该样例输出是一条满足所有条件的迹(trail)。

例如,以下输出同样可被接受:

约束条件

  • 1≤T≤501\le T\le 50
  • 3≤N≤10003\le N\le 1000
  • 所有测试用例的 NN 之和不超过 10001000。
  • 所有输入值均为整数。

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

首页