首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2013-03-27 
CF 286A(Lucky Permutation-数列找规律)A. Lucky Permutationtime limit per test2 secondsmemory limit p

CF 286A(Lucky Permutation-数列找规律)
A. Lucky Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

A permutation 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).

A lucky permutation is such permutation p, that any integer i (1?≤?i?≤?n) meets this condition ppi?=?n?-?i?+?1.

You have integer n. Find some lucky permutation p of size n.

Input

The first line contains integer n (1?≤?n?≤?105) — the required permutation size.

Output

Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist.

Otherwise, print n distinct integers p1,?p2,?...,?pn (1?≤?pi?≤?n) after a space — the required permutation.

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-数列觅规律)


#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;}


热点排行