Hexagon
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 167 Accepted Submission(s): 101
Special Judge
Problem Description
It is preferrable to read the pdf statment.
If the world is a hexagon, I will take as many turns as possible before reaching the end.
Cuber QQ has constructed a hexagon grid with radius n. This will be better if explained in a picture. For example, this is a hexagon grid with radius 3:
He challenges you take a perfect tour over the hexagon, that is to visit each cell exactly once. Starting from any point in the grid, you can move to any adjacent cell in each step. There are six different directions you can choose from:
Of course, if you are on the boundary, you cannot move outside of the hexagon.
Let D(x,y) denote the direction from cell x to y, and sequence A denotes your route, in which Ai denotes the i-th cell you visit. For index i (1
Maximize the number of turning while ensuring that each cell is visited exactly once. Print your route. If there are multiple solution, print any.
Input
The first line of the input contains a single integer T (1≤T≤104), denoting the number of test cases.
Each of the next T cases:
The first line contains an integer n (2≤n≤500).
It is guaranteed that the sum of n doesn’t exceed 2⋅104.
Output
For each test case, output one line contains a string with 3(n−1)n characters. The i-th character is D(Ai,Ai+1).
Sample Input
1
2
Sample Output
313456
题意:
要求构造拐弯次数最多并且遍历全部路的路径,方向为123456。输出路径
题解:
分别分成奇数和偶数的情况,然后奇数内三层都是一样的,特殊处理一下六边形出来的第一个边,还有六边形的最后一条边;偶数的内两层都是一样的,然后特殊处理一下六边形的最后一条边。每次加2层是加4步。
Code:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include