Solution to a problem P6161 [[Cnoi2020] high-dimensional]

This question when I race because of various metaphysical error, leading to toss a half, in the last \ (20 \) after just minutes \ (\ ldots \ ldots \)

First of all, this question is too long-winded, but in fact the title is intended to simplify it, we will find. For \ (I \) dimension, removing the start and end path length is \ (. 1-I \) , requires these nodes different from each other. We analyze, \ (i \) dimensional in fact there \ (2 ^ i-2 \ ) nodes, we put them a division, you will find the result is \ (i \) , is that there \ (i \) paths.(More than likely I'm blind in yy)

How to obtain each path it? May all of a sudden think of it is to enumerate and determine whether to repeat with a hash table, but the practice space and time-consuming and expensive, so I have to use a flash method at the time of the game (fireworks)


The general idea is to use a one-dimensional array, the subscript \ (I \) corresponds to a node in the operation path \ (I \) to be changed dimensions . Is initialized to \ (0 \) , corresponding to the first \ (1 \) dimension. After the first operation, it will add \ (1 \) , leaving the path; and, after observation, we find that, \ (I + 1} F_ {\) corresponding to that dimension \ (F_i \) of dimension plus \ (1 \) , you can meet the subject requirements.

But there may be a problem, if you have been added to go, \ (F_i \) sooner or later will exceed \ (the n-\) . How to do? Then take a mold chant! That \ (. 1 + F_ {I} = (F_i +. 1) \ n-MOD \) .

Similarly, the operation to be \ (F_i \ the gets F_i +. 1 \) .

As for the principle of this method, I do not know, just a guess at the game. If anyone dalao want to prove this method, you can look at yourself. If I think of the future proof, it will fill up.

If you have not yet been understood, in conjunction with codes eat better.

AC Code:

#include<bits/stdc++.h>
using namespace std;
long long n,f[65];    
long long last;  //终点的压缩坐标。 
string now;  //now 为当前节点的坐标。 
long long po(long long x)  //手打一个计算幂的函数。 
{
    long long re=1;
    for(register long long i=0;i<x;i++) re*=2;
    return re;
}
long long zip(string a)   //如题,微改的压缩函数。 
{
    long long size=a.length();
    long long h=0;
    for(register long long i=size-1;i>=0;i--) 
         if(a[i]=='1')
            h+=po(i);
    return h;
}
int main()
{
    cin>>n;
    cout<<n<<endl;   //n 条路径 。 
    last=po(n)-1;  
    for(register long long i=0;i<n;i++)
    {
        cout<<0<<" ";  //起点 
        for(register long long j=0;j<n;j++)
            now+='0';  //这是 now 的初始化,将坐标赋为 0。 
        for(register long long j=1;j<n;j++)
        {
            now[f[j]]='1';   //精髓,将需改变的维度改变。 
            f[j+1]=(f[j]+1)%n;  //求出 f[i+1]。 
            f[j]=(f[j]+1)%n;    //为防止下一条路径重复,本身也要改变。 
            long long g=zip(now);
            cout<<g<<" ";  //输出压缩后的路径。 
        }
        cout<<last<<endl;
        now.clear();  //记住!!!一定要清空。 
    }
    return 0;
}

PS: And this question I always do not understand is: I start the game with cmath pow function to compute power , but would have been three points WA; then cuffed seeking a power function on before (large fog

Guess you like

Origin www.cnblogs.com/win10crz/p/12404466.html