按照题意构造集合即可

注意无解情况的判断

#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. Day8 面向对象

    一.面向对象和面向过程 各位,我们现在如果要将大象放冰箱,用面向过程怎么实现呢? 1.把大象放到冰箱里 第一步:把冰箱门打开 第二步:把大象放进去 第三步:把门关上 def open_fridge_d ...

  2. sitecore系列教程之如何以编程方式将访客数据关联到联系人卡片

      在我之前关于Sitecore体验资料的帖子中,我们看到了我们如何了解访问者的一切,包括访问他们在访问期间触发的事件.在这篇博客文章中,我将引导您完成识别匿名用户并将用户访问与联系人记录联系起来的过 ...

  3. SourceTree 使用

    删除分支 新建一个分支 A 后,要想把 A 分支删除掉,只需跳到另一个分支上去,选中 A 分支然后右击,在弹出的菜单栏中选中 [删除 A 分支]即可: 在分支下建一个文件夹 左上的然后弹出选框,在[新 ...

  4. 输入输出无依赖型函数的GroovySpock单测模板的自动生成工具(上)

    目标 在<使用Groovy+Spock轻松写出更简洁的单测> 一文中,讲解了如何使用 Groovy + Spock 写出简洁易懂的单测. 对于相对简单的无外部服务依赖型函数,通常可以使用 ...

  5. flask 操作数据库(分类)

    数据库 数据库是大多数动态web程序的基础设施,只要你想把数据存下来,就离不开数据库. 这里所说的数据库指的是有存储数据的单个或多个文件组成的集合,它是一种容器,可以类比文文件柜.而人们通常使用数据库 ...

  6. js函数常见的写法以及调用方法

    写在前面:本文详细的介绍了5中js函数常见的写法以及调用的方法,平时看别人代码的时候总是看到各种不同风格的js函数的写法.不明不白的,找了点资料,做了个总结,需要的小伙伴可以看看,做个参考.1.常规写 ...

  7. javaweb笔记—02

    1.compatible:adj. 兼容的:能共处的:可并立的2.web所有的请求都是http请求,http请求默认的编码是ISO-8859-1,不支持utf-8,要统一设置前台和后台一样,才不会乱码 ...

  8. django field

    name=models.CharField(max_length=30,unique=True,verbose_name='姓 名')    birthday=models.DateField(bla ...

  9. gcc对c++标准的支持

    GCC 4.8.1完全支持c++11核心部分,对应的glibc为2.17 gcc 4.9支持c++11正则表达式,卧槽...4.8.5会报terminate called after throwing ...

  10. ACM札记

    1. 逗号表达式 在“计蒜客“的ACM教程中,看到这样一段很好的代码: int n; while (scanf("%d", &n), n) { //do something ...