按照题意构造集合即可

注意无解情况的判断

#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==){
printf("No\n");
return ;
}
sum=(n+)*n/;
// printf("%d\n",sum);
for(int i=;i<=sum;i++){
for(int j=;j<=sqrt(i);j++){
if(i%j==){
if(j!=i/j){
if(j!=&&sum!=i){
if((sum-i)%j==){
vector<int> ax,bx;
int cnta=,cntb=;
int now=n;
for(int k=i;k>;){
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\n");
printf("%d ",cnta);
for(int i=;i<ax.size();i++)
printf("%d ",ax[i]);
printf("\n");
printf("%d ",cntb);
for(int i=;i<bx.size();i++)
printf("%d ",bx[i]);
printf("\n");
return ;
}
}
if(i/j!=&&sum!=i){
if((sum-i)%(i/j)==){
vector<int> ax,bx;
int cnta=,cntb=;
int now=n;
for(int k=i;k>;){
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\n");
printf("%d ",cnta);
for(int i=;i<ax.size();i++)
printf("%d ",ax[i]);
printf("\n");
printf("%d ",cntb);
for(int i=;i<bx.size();i++)
printf("%d ",bx[i]);
printf("\n");
return ;
}
}
}
else{
if(j!=&&i!=sum)
if((sum-i)%j==){
vector<int> ax,bx;
int cnta=,cntb=;
int now=n;
for(int k=i;k>;){
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\n");
printf("%d ",cnta);
for(int i=;i<ax.size();i++)
printf("%d ",ax[i]);
printf("\n");
printf("%d ",cntb);
for(int i=;i<bx.size();i++)
printf("%d ",bx[i]);
printf("\n");
return ;
}
}
}
}
}
printf("No\n");
return ;
}

题解——Codeforces Round #508 (Div. 2) T2 (构造)的更多相关文章

  1. 题解——Codeforces Round #508 (Div. 2) T3 (贪心)

    贪心的选取最优解 然后相减好 记得要开long long #include <cstdio> #include <algorithm> #include <cstring ...

  2. 题解——Codeforces Round #508 (Div. 2) T1 (模拟)

    依照题意暴力模拟即可A掉 #include <cstdio> #include <algorithm> #include <cstring> #include &l ...

  3. Codeforces Round #508 (Div. 2)

    Codeforces Round #508 (Div. 2) http://codeforces.com/contest/1038 A #include<bits/stdc++.h> us ...

  4. [题解] Codeforces Round #549 (Div. 2) B. Nirvana

    Codeforces Round #549 (Div. 2) B. Nirvana [题目描述] B. Nirvana time limit per test1 second memory limit ...

  5. Codeforces 1038F Wrap Around (Codeforces Round #508 (Div. 2) F) 题解

    写在前面 此题数据量居然才出到\(n=40\)???(黑人问号)以下给出一个串长\(|S|=100,n=10^9\)的题解. 题目描述 给一个长度不超过\(m\)的01串S,问有多少个长度不超过\(n ...

  6. Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)

     E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范 ...

  7. Codeforces Round #272 (Div. 1) B 构造 math

    http://www.codeforces.com/contest/477/problem/C 题目大意:给你n个集合,每个集合里面有四个数字,他们的gcd是k,输出符合条件的集合中m,m为集合中最大 ...

  8. Codeforces Round #508 (Div. 2) D. Slime

    D. Slime 题目链接:https://codeforces.com/contest/1038/problem/D 题意: 给出两个数,然后每次可以对相邻的两个数合并,比如x,y,那么合并过后就是 ...

  9. CF1103C Johnny Solving (Codeforces Round #534 (Div. 1)) 思维+构造

    题目传送门 https://codeforces.com/contest/1103/problem/C 题解 这个题还算一个有难度的不错的题目吧. 题目给出了两种回答方式: 找出一条长度 \(\geq ...

随机推荐

  1. Chess (SG + 状态压缩预处理)

    #include<bits/stdc++.h> #define bit(t) (1 << t) using namespace std; <<; ;//k是集合s的 ...

  2. MySql 应用语句

    [1]MySQL基础语句 -- 查询mysql版本号 SELECT VERSION(); -- 创建数据库 DROP DATABASE IF EXISTS study; -- 如果存在先删除 CREA ...

  3. python glob 模块

    glob模块用来查找文件目录和文件,可以和常用的find功能进行类比.glob支持*?[]这三种通配符.返回的数据类型是list.常见的两个方法有glob.glob()和glob.iglob(),ig ...

  4. python 类似java的三目运算符

    python中没有其他语言中的三元表达式,不过有类似的实现方法 其他语言中,例如java的三元表达式是这样 int a = 1; String b = ""; b = a > ...

  5. localStorage单页面及不同页面监听变动

    分析 H5本地存储有两个API,一个是Web Storage,还有一个是Web SQL.不管是哪一个,都是基于JavaScript语言来使用,而Web Storage提供了两种存储类型 API:  s ...

  6. 听 Fabien Potencier 谈Symfony2 之 《What is Symfony2 ?》

    Symfoy2 是什么? PHP世界里又一广受关注的web MVC框架? Fabien Potencier 却不这么说! Fabien Potencier这样定义Symfoy2 是个什么东西: 首先, ...

  7. ul点击li,增加样式

    用户首次绑定后,需要选择一款头像 <!--imgList头像列表--><el-row class="regModel1"> <el-col :span ...

  8. Caterpillar sis service information training and software

    Cat et sis caterpillar heavy duty truck diagnostics repair. Training demonstration allows.cat electr ...

  9. js获取浏览器信息

    function message() { txt = "<p>浏览器代码名: " + navigator.appCodeName + "</p>& ...

  10. kali linux常用软件配置记录

    首先膜一波,认真细致,简明有效. 感谢原博主的分享,留作参考. https://www.cnblogs.com/youfang/p/5272746.html