Minimum Euler Cycle

D - Minimum Euler Cycle

首先最重要的是构造规则:当\(n=5\)\((1 2 1 3 1 4 1 5 (2 3 2 4 2 5 (3 4 3 5 (4 5 ()))) 1)\)

赛时需要想到,如果发现一个东西构造起来很麻烦的话,那么有很大几率是自己的思路错了

#include<bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn=1e5+5;
ll s[maxn];
int n;
int cal(ll x){
    if(x==s[n]) return 1;
    int a=lower_bound(s+1,s+n+1,x)-s;
    int b=x-s[a-1];
    if(b&1) return a;
    else return b/2+a;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;cin>>t;
    while(t--){
        ll l,r;cin>>n>>l>>r;
        for(int i=1;i<=n;++i)
            s[i]=s[i-1]+2*(n-i);
        s[n]++;
        for(ll i=l;i<=r;++i)
            cout<<cal(i)<<" ";
        cout<<"\n";
    }
}
posted @ 2020-04-12 21:22  caoanda  阅读(202)  评论(0编辑  收藏  举报