【题解 CF1205A Almost Equal】
作者:互联网
【Analsis】
因为任意两个和相差最多为1,可以构造答案,比如
n=3 -> $1, 4, 5, 2, 3, 6 $
n为奇数时 [小],[大],[小],[大],......[小],[大] 这样是可以的
n为偶数时 [小],[大],[小],[大],[小]......[大],[小]可以发现这样不行,然后就做完了
【Code】
#include <cstdio>
#include <set>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
namespace IO
{
inline char gc()
{
static char s[1<<20|1]={0},*p1=s,*p2=s;
return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
}
// inline char gc() { return getchar(); }
inline long long read()
{
long long ret=0;bool flag=0;char c=gc();
while ((c<'0')|(c>'9')) flag ^= !(c^'-'),c=gc();
while ((c>='0')&(c<='9')) ret=(ret<<1)+(ret<<3)+(c^'0'),c=gc();
return flag?-ret:ret;
}
char OutputAns[1<<20|1],*OutputCur = OutputAns;
inline void output()
{
OutputCur -= fwrite(OutputAns,1,OutputCur - OutputAns,stdout);
}
inline void print(long long ans)
{
char s[20]={0};
if (OutputCur - OutputAns + sprintf(s,"%I64d",ans) >> 20) output();
OutputCur += sprintf(OutputCur,"%I64d",ans);
}
inline void printc(char c)
{
if (OutputCur - OutputAns + 1 >> 20) output();
*(OutputCur++) = c;
}
}
using IO::read;
using IO::print;
using IO::printc;
using IO::output;
const int M = 1e5 + 11;
int A[M<<1];
int n;
inline void Go1()
{
puts("YES");
printf("1 2\n");
exit(0);
}
int main(void)
{
n = read();
if (n == 1) Go1();
if (!(n & 1)) puts("NO");
else
{
puts("YES");
bool opt = 0;
for (int i = 1;i <= n; ++i)
{
opt ^= 1;
if (opt) A[i] = (i<<1) - 1, A[i + n] = i<<1;
else A[i] = i<<1, A[i + n] = (i<<1) - 1;
}
for (int i = 1;i <= (n<<1); ++i)
print(A[i]), printc(' ');
printc('\n'); output();
} return 0;
}
标签:OutputCur,Almost,题解,Equal,char,IO,output,using,include 来源: https://blog.csdn.net/zyn_615/article/details/99719609