zoukankan      html  css  js  c++  java
  • NOIP 模拟 $89; m 子集$

    题解 (by;zjvarphi)

    每次直接来回一条龙选,如果 (frac{n}{k}) 是奇数,那么将连续的三行取出来,凑一下。

    具体实现就是对其中两行凑出来公差为 (1) 的等差数列,可以先算出来中位数,再两两配对。

    记得特判无解,但 (n=1,k=1) 时是有解的。

    Code
    #include<bits/stdc++.h>
    #define ri signed
    #define pd(i) ++i
    #define bq(i) --i
    #define func(x) std::function<x>
    namespace IO{
        char buf[1<<21],*p1=buf,*p2=buf;
        #define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?(-1):*p1++
        #define debug1(x) std::cerr << #x"=" << x << ' '
        #define debug2(x) std::cerr << #x"=" << x << std::endl
        #define Debug(x) assert(x)
        struct nanfeng_stream{
            template<typename T>inline nanfeng_stream &operator>>(T &x) {
                bool f=false;x=0;char ch=gc();
                while(!isdigit(ch)) f|=ch=='-',ch=gc();
                while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=gc();
                return x=f?-x:x,*this;
            }
        }cin;
    }
    using IO::cin;
    namespace nanfeng{
        #define FI FILE *IN
        #define FO FILE *OUT
        template<typename T>inline T cmax(T x,T y) {return x>y?x:y;}
        template<typename T>inline T cmin(T x,T y) {return x>y?y:x;}
        using ll=long long;
        static const int N=1e6+7;
        int st[N][2],T,n,k;
        inline int main() {
            FI=freopen("subset.in","r",stdin);
            FO=freopen("subset.out","w",stdout);
            cin >> T;
            for (ri z(1);z<=T;pd(z)) {
                cin >> n >> k;
                if (n==1) {printf("Yes
    1
    ");continue;}
                ll al=1ll*n*(n+1)>>1;
                if (al%k) {printf("No
    ");continue;}
                int nm=n/k,cnt=0;
                if (nm&1) {
                    if (nm==1) {printf("No
    ");continue;}
                    printf("Yes
    ");
                    const int bs=k<<1;
                    int hf=n+n-bs+1+(k>>1),lim=n-bs,bg=0;
                    for (ri i(k);i>0;i-=2) {
                        st[++bg][0]=lim+i;
                        st[bg][1]=hf-st[bg][0];
                        --hf;
                    }
                    for (ri i(k-1);i>0;i-=2) {
                        st[++bg][0]=lim+i;
                        st[bg][1]=hf-st[bg][0];
                        --hf;
                    }
                    for (ri i(1);i<=k;pd(i)) {
                        const int tmp=bs-(i<<1)+1;
                        for (ri j(i);j<=lim-k;j+=bs) printf("%d %d ",j,j+tmp);
                        printf("%d %d %d
    ",lim-k+i,st[i][0],st[i][1]);
                    }
                } else {
                    printf("Yes
    ");
                    const int bs=k<<1;
                    for (ri i(1);i<=k;pd(i)) {
                        const int tmp=bs-(i<<1)+1;
                        for (ri j(i);j<=n;j+=bs) printf("%d %d ",j,j+tmp);
                        printf("
    ");
                    }
                }
            }
            return 0;
        }
    }
    int main() {return nanfeng::main();}
    
  • 相关阅读:
    November 07th, 2017 Week 45th Tuesday
    November 06th, 2017 Week 45th Monday
    November 05th, 2017 Week 45th Sunday
    November 04th, 2017 Week 44th Saturday
    November 03rd, 2017 Week 44th Friday
    Asp.net core 学习笔记 ( Area and Feature folder structure 文件结构 )
    图片方向 image orientation Exif
    Asp.net core 学习笔记 ( Router 路由 )
    Asp.net core 学习笔记 ( Configuration 配置 )
    qrcode render 二维码扫描读取
  • 原文地址:https://www.cnblogs.com/nanfeng-blog/p/15511455.html
Copyright © 2011-2022 走看看