题解——Codeforces Round #508 (Div. 2) T2 (构造)

Posted dreagonm

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了题解——Codeforces Round #508 (Div. 2) T2 (构造)相关的知识,希望对你有一定的参考价值。

按照题意构造集合即可

注意无解情况的判断

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
int n,sum;
int main(){
  scanf("%d",&n);
  if(n==1){
    printf("No
");
    return 0;
  }
  sum=(n+1)*n/2;
//  printf("%d
",sum);
  for(int i=2;i<=sum;i++){
      for(int j=1;j<=sqrt(i);j++){
        if(i%j==0){
        if(j!=i/j){
        if(j!=1&&sum!=i){
            if((sum-i)%j==0){
              vector<int> ax,bx;
              int cnta=0,cntb=0;
              int now=n;
              for(int k=i;k>0;){
                if(k>=now){
                  k-=now;
                  cnta++;
                  ax.push_back(now);
                  now--;
                }
              else{
                cntb++;
                bx.push_back(now);
                now--;
                }
              }
              while(now){
                bx.push_back(now);
                now--;
                cntb++;
              }
              printf("Yes
");
              printf("%d ",cnta);
              for(int i=0;i<ax.size();i++)
                printf("%d ",ax[i]);
              printf("
");
              printf("%d ",cntb);
              for(int i=0;i<bx.size();i++)
                printf("%d ",bx[i]);
              printf("
");
              return 0;
            }
          }
        if(i/j!=1&&sum!=i){
          if((sum-i)%(i/j)==0){
            vector<int> ax,bx;
            int cnta=0,cntb=0;
              int now=n;
              for(int k=i;k>0;){
                if(k>=now){
                  k-=now;
                  cnta++;
                  ax.push_back(now);
                  now--;
                }
              else{
                cntb++;
                bx.push_back(now);
                now--;
                }
              }
              while(now){
                bx.push_back(now);
                now--;
                cntb++;
              }
              printf("Yes
");
              printf("%d ",cnta);
              for(int i=0;i<ax.size();i++)
                printf("%d ",ax[i]);
              printf("
");
              printf("%d ",cntb);
              for(int i=0;i<bx.size();i++)
                printf("%d ",bx[i]);
              printf("
");
              return 0;
            }
          }
        }
      else{
        if(j!=1&&i!=sum)
          if((sum-i)%j==0){
            vector<int> ax,bx;
            int cnta=0,cntb=0;
              int now=n;
              for(int k=i;k>0;){
                if(k>=now){
                  k-=now;
                  cnta++;
                  ax.push_back(now);
                  now--;
                }
              else{
                cntb++;
                bx.push_back(now);
                now--;
                }
              }
            while(now){
              bx.push_back(now);
              now--;
              cntb++;
            }
            printf("Yes
");
            printf("%d ",cnta);
            for(int i=0;i<ax.size();i++)
              printf("%d ",ax[i]);
            printf("
");
            printf("%d ",cntb);
            for(int i=0;i<bx.size();i++)
              printf("%d ",bx[i]);
            printf("
");
            return 0;
          }
        }
      }
    }
  }
  printf("No
");
  return 0;
}

 

以上是关于题解——Codeforces Round #508 (Div. 2) T2 (构造)的主要内容,如果未能解决你的问题,请参考以下文章

题解——Codeforces Round #508 (Div. 2) T2 (构造)

Codeforces Round #508 (Div. 2)

Codeforces Round #815 (Div. 2) 题解

Codeforces Round #805 (Div. 3) 题解

Codeforces Educational Codeforces Round 54 题解

Codeforces Round #637 (Div. 2) 题解