编程介的小学生 2017-08-13 15:32 采纳率: 20.5%
浏览 933
已采纳

Perfect Permutation

Description

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.
Input

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

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.
Sample Input

1
2
4
Sample Output

1
0
3 2 4 1

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-08-27 15:15
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效