首页 > 其他分享 >CF 286A(Lucky Permutation-数列找规律)

CF 286A(Lucky Permutation-数列找规律)

时间:2022-10-25 10:01:01浏览次数:38  
标签:cout int CF Lucky 286A output input include size


A. Lucky Permutation



time limit per test



memory limit per test



input



output



p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).

p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.

n. Find some lucky permutation p of size n.



Input



n (1 ≤ n ≤ 105) — the required permutation size.



Output



p of size n

n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n)

If there are multiple answers, you can print any of them.



Sample test(s)



input



1



output



1



input



2



output



-1



input



4



output



2 4 1 3



input



5



output



2 5 3 1 4



找规律

如图所示

CF 286A(Lucky Permutation-数列找规律)_i++



#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<iostream>
using namespace std;
int n;
int main()
{
cin>>n;
if (n%4>1)
{
cout<<"-1\n";
return 0;
}
for (int i=1;i<=n/2;i++)
{
if (i%2) cout<<i+1<<' ';
else cout<<(n-i+2)<<' ';
}
int m=n/2;
if (n%4==1)
{
cout<<m+1;
if (m+1<n) cout<<' ';
m++;
}
for (int i=m+1;i<n;i++)
{
if ((i-m)%2) cout<<n-i<<' ';
else cout<<i-1<<' ';
}
if (m+1<n) cout<<(n-1);
cout<<endl;
return 0;
}



标签:cout,int,CF,Lucky,286A,output,input,include,size
From: https://blog.51cto.com/u_15724837/5794021

相关文章

  • 1.1 WCF SOA架构和webservice
    1.什么是SOA?SOA全称:面向服务架构(serviceOrientedArchitecture),它是一种组件架构模式。一、定义1.WebService:严格来说是行业标准,不是技术,使用XML扩展标记语言来表示数据......
  • CF1716F
    与CF932E,CF1278F其实差不多捏。首先\(m\)中奇数个数是\(\left\lceil\frac{m}{2}\right\rceil\),偶数个数是\(\left\lfloor\frac{m}{2}\right\rfloor\)。下文为了方便......
  • [CF1753C]Wish I Knew How to Sort
    做题时间:2022.10.25\(【题目描述】\)给定一个长度为\(n\)的01序列\(a\)和一种操作,你需要用这种操作将序列从小到大排序。操作为:等概率随机选择两个位置\(i,j(i<j)\)......
  • CF1278F
    与CF932E其实是差不多的捏设\(p=\dfrac{1}{m},q=1-p\),那么枚举第一张是王牌的次数,有如下式子:\[\sum_{i=1}^{n}\binom{n}{i}p^iq^{n-i}i^k\]后面那个\(i^k\)可以展......
  • CF1744B Even-Odd Increments
    简要题意\(T\)组数据,每组数据给定一个长度为\(n\)的数列,有\(q\)次操作,共有两种操作:\(\texttt{0x}\),给数列中所有偶数加上\(x\);\(\texttt{1x}\),给数列中所有奇......
  • CF932E
    先介绍这样一个等式:\[n^m=\sum_{i=1}^{m}\begin{Bmatrix}m\\i\end{Bmatrix}\timesi!\times\binom{n}{i}\]等式左边的组合意义是\(m\)个不同的球放入\(n\)个不同的......
  • CF1753A1
    前言题目传送门!更好的阅读体验?提供一种更加好理解的方法。思路关键点:只要凑够就行,不需要区间数量最小。首先,每个数是\(-1\)或\(1\),说明\(n\)为奇数时,必定无解。......
  • CF1753B 题解
    前言题目传送门!更好的阅读体验?其实挺简单的,赛时多打了个等号,被人叉了。思路关键是\(n!\times(n+1)=(n+1)!\)。原因很显然:\((1\times2\times\cdots\tim......
  • CF1716E
    感觉以前遇到过类似的操作,但是还是不会(考虑到两次相同的操作会相互抵消,并且答案与操作顺序无关,所以答案至多\(2^n\)种,考虑预处理出来。首先你得会分治求最大子段和,维护......
  • CF1732A Bestie
    思路观察数据\(n\le20\)直接暴力。我们直接算所有数的\(GCD\),然后枚举\(1\)~\(n\)的每一个数要不要选,然后选的话,就把原来的\(GCD\)和当前枚举的数\(GCD\)一下,最后求最......