1976 Queen Series

Source: Internet
Author: User

1976 Queen Series

time limit: 1 sspace limit: 128000 KBtitle level: Golden Gold SolvingView Run ResultsTitle Description Description

The integer sequence of 1 to N (1,2,3,......,n) is scrambled and changed to sequence a (A[1],a[2],a[3],......,a[n]). If this sequence satisfies a[a[i]]=n+1-i for any i∈{1,2,3,......,n}, then this sequence is called the Queen sequence of length N.

Now give you the length n, please output the Queen sequence with the smallest dictionary order.

The so-called dictionary order is the smallest, that is a[1] the smallest, on this basis a[2] the smallest, on this basis a[3] the smallest ...

Enter a description Input Description

A total of one row, which is an integer n.

Output description Output Description

A total of one row, there are I integers, separated by a space (no space at the end of the line), the first integer is A[i]. Where A is the Queen sequence with the smallest dictionary order length n. If no such sequence exists, output a 0.

Sample input Sample Input

INPUT1:

3

Input2:

4

INPUT3:

5

Sample output Sample Output

OUTPUT1:

0

Output2:

2 4 1 3

OUTPUT3:

2 5 3) 1 4

Data range and Tips Data Size & Hint

There is no queen sequence with a length of 3.

2 4 1 3 is the Queen sequence with the smallest dictionary order length of 4.

2 5 3 1 4 is a queen sequence with a minimum dictionary length of 5.

For 20% of data, n≤10; for 50% data, n≤1000; for 100% of data, 1≤n≤200000.

Category labels Tags Click here to expand

This rule, I am also drunk.

Code:

#include <cstdio>#include<iostream>using namespacestd;inta[200010],n;intMain () {scanf ("%d",&N); if(n%4>1) {printf ("0\n");return 0;}  for(intI=1; i<=n/4;++i) {a[2*i-1]=2*i; a[2*i]=n+2-2*i; A[n-2*i+2]=n+1-2*i; A[n-2*i+1]=2*i-1; }    if(n%2==1) a[n/2+1]= (n+1)/2;  for(intI=1; i<=n;i++) printf ("%d", A[i]); return 0;} 

1976 Queen Series

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.