Codeforces Round #580 (Div. 2) C. Almost Equal (思维+数学)

Codeforces Round #580 (Div. 2) C. Almost Equal (思维+数学)_第1张图片

题意:
给定n,在一个2n多边形内满足相邻三条边x,a,b,y满足
x+a+b=a+b+y+1或者
x+a+b=a+b+y-1

n为奇数的时候可以满足,为偶数的时候不满足输出NO

typedef long long ll;
const ll maxn=2e5+10;
ll n,a[maxn];
int main() {
    scanf("%lld",&n);
    if(n&1) {
        puts("YES");
        for(ll i=1; i<=n; i++) {
            if(i&1) { 
                a[i]=2*i-1;
                a[i+n]=2*i;
            } else {
                a[i]=2*i;
                a[i+n]=2*i-1;
            }
        }
        for(int i=1; i<=2*n; i++) {
            printf("%lld%c",a[i],i==2*n?'\n':' ');
        }
    } else {
        puts("NO");
    }
    return 0;
}

你可能感兴趣的:(CodeForces)