HDU6862 Hexagon(2020杭电暑期多校训练第八场)

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<i<|A|), if D(Ai−1,Ai)≠D(Ai,Ai+1), we say there is a turning on cell i.

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<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
#include <fstream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#define ll long long
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0),eps=1e-8;
const ll mod =  998244353;
const int maxn=1e5+5;
struct node
{
    double x,y;
} cir[5],p1,p2;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        if(n%2==0)//图一
        {
            printf("461234");//图一的底
            if(n>2)
            {
                int num=5;
                int xx=2;
                while(xx<n)
                {
                    printf("34");
                    int x=6,y=4;
                    for(int k=0; k<6; k++)
                    {
                        if(k<5)
                        {

                            for(int i=0; i<num; i++)
                            {
                                if(i%2==0)
                                    printf("%d",x);
                                else
                                    printf("%d",y);
                            }
                        }
                        else
                        {
                            for(int i=0; i<num-3; i++)//特殊处理六边形的最后一条边
                            {
                                if(i%2==0)
                                    printf("%d",x);
                                else
                                    printf("%d",y);
                            }
                        }
                        x=(x)%6+1;
                        y=(y)%6+1;
                    }
                    printf("4");
                    num+=4;
                    xx+=2;
                }
            }
        }
        else//图二
        {
            printf("546126231342453564");//图二的底
            if(n>3)
            {
                int num=7;
                n-=2;
                while(n>1)
                {
                    printf("546");

                    int x=1,y=5;
                    for(int i=0; i<num-2; i++)//第一条边处理
                    {
                        if(i%2==0)
                            printf("%d",x);
                        else
                            printf("%d",y);
                    }
                    x=(x)%6+1;
                    y=(y)%6+1;
                    for(int k=0; k<4; k++)
                    {
                        for(int i=0; i<num; i++)
                        {
                            if(i%2==0)
                                printf("%d",x);
                            else
                                printf("%d",y);
                        }
                        x=(x)%6+1;
                        y=(y)%6+1;
                    }
                    for(int i=0; i<num-1; i++)//最后一条边处理
                    {
                        if(i%2==0)
                            printf("%d",x);
                        else
                            printf("%d",y);
                    }
                n-=2;
                num+=4;//每次加4步
                }

            }
        }
        printf("\n");
    }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值