程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> ai-Perfect Permutation

ai-Perfect Permutation

編輯:編程解疑
Perfect Permutation

A permutation of 1..n {An} is called a Perfect Permutation if the sequence {|Ai − i|} is a permutation of 0..(n − 1).

For example, {3, 2, 4, 1} is a perfect permutation for {2, 0, 1, 3} is a permutation of 0..3.

Given an integer n, your mission is to find a perfect permutation of 1..n.

輸入描述

The input consists of several lines. Each line contains a positive integer n ≤ 1000.

輸出描述

The output contains one line for each line in the input. If no such perfect permutation exists, output a single number 0 otherwise the perfect permutation. If more than one solution exist, you can output anyone.

輸入例子

1

2

4

輸出例子

1

0

3 2 4 1

最佳回答:


http://www.cppblog.com/Rich-cw/archive/2009/12/19/103543.aspx

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved