2018icpc Qingdao F. Tournament (Construction)

Title :

Given n knights, play k battles, each knight can only play against another knight once, if A plays B and C plays D in the ith round, then if A plays C (D) in the jth round, then B must be Versus D©. Ask if it is possible to form k-games. Lexicographic order from smallest to largest.

Analysis :

We look at the smallest lexicographical order, that is, the best we can think of is nothing more than

1 2 3 4 5 6 7 8 (however this doesn't work, I can't play against me)

2 1 4 3 6 5 8 7 (then we have to choose the best, for sure 12 is swapped, 34 is swapped)

34127856

This is how it ends

[External link image transfer failed, the source site may have an anti-leech mechanism, it is recommended to save the image and upload it directly (img-8bMZlsNV-1635941280451) (https://secure.wostatic.cn/static/nr6MSRJBGp92FDUiM66d4z/image.png)]

By observing, we can find the law, first the length is 2, then the length is 4, then the length is 2, then 8, then 2, then 4, then 2. Does it look like a tree array!

[External link image transfer failed, the origin site may have anti-leech mechanism, it is recommended to save the image and upload it directly (img-0yxZt6nR-1635941280455) (https://secure.wostatic.cn/static/rvnAJFRWkUoboSwkEgUpHq/image.png)]

Then we only need to judge whether it is feasible, a total of lowbit(n)-1 rounds can be performed and it is impossible to achieve beyond this.

Then we just need to construct who is playing against whom each round.

big guy

/// 欲戴皇冠,必承其重。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<string, string> pii;
typedef unsigned long long ull;

#define x first
#define y second
#define PI acos(-1)
#define inf 0x3f3f3f3f
#define lowbit(x) ((-x)&x)
#define debug(x) cout << #x << ": " << x << endl;

const int MOD = 998244353;
const int mod = 998244353;
const int N = 5e5 + 10;
const int dx[] = {
    
    0, 1, -1, 0, 0, 0, 0};
const int dy[] = {
    
    0, 0, 0, 1, -1, 0, 0};
const int dz[] = {
    
    0, 0, 0, 0, 0, 1, -1};
int day[] = {
    
    0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

ll n, m;
ll a[N];
void solve()
{
    
    
    scanf("%lld%lld",&n,&m);    
    if(m>lowbit(n)-1){
    
    
        puts("Impossible");
    }else {
    
    
        for(int i=1;i<=n;i++){
    
    
            a[i]=i;
        }
        for(ll i =1;i<=m;i++){
    
    
            ll len=lowbit(i);
            for(ll j=1;j<=n;j+=(len<<1)){
    
    
                for(ll k=0;k<len;k++){
    
    
                    swap(a[j+k],a[j+len*2-1-k]);
                }
            }
            for(int j=1;j<n;j++){
    
    
                cout<<a[j]<<" ";
            }
            cout<<a[n]<<endl;
        }
    }
}    
int main()
{
    
    
    ll t = 1;
    scanf("%lld", &t);
    while(t--)
    {
    
    
        solve();
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326247264&siteId=291194637