题解——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==){
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 ;
}
上一篇:Gradle 1.12用户指南翻译——第二十八章. Jetty 插件


下一篇:WPF控件开源资源