博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva11630 or hdu2987 Cyclic antimonotonic permutations(构造水题)
阅读量:5334 次
发布时间:2019-06-15

本文共 2447 字,大约阅读时间需要 8 分钟。

转载请注明出处:           ——by fraud

 

Cyclic antimonotonic permutations

Time Limit: 20000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
A permutation is a sequence of integers which contains each integer from 1 to n exactly once. In this problem we are looking for permutations with special properties: 
1. Antimonotonic: for each consecutive 3 values p
i-1, p
i, p
i+1 (1 < i < n), p
i should either be the smallest or the biggest of the three values. 
2. Cyclic: The permutation should consist of only one cycle, that is, when we use p
i as a pointer from i to p
i, it should be possible to start at position 1 and follow the pointers and reach all n positions before returning to position 1. 
 

Input
The input file contains several test cases. Each test case consists of a line containing an integer n, (3 ≤ n ≤ 10
6), the number of integers in the permutation. Input is terminated by n=0. 
 

Output
For each test case print a permutation of the integers 1 to n which is both antimonotonic and cyclic. In case there are multiple solutions, you may print any one. Separate all integers by whitespace characters.
 

Sample Input
3 5 10 0
 

Sample Output
3 1 2 4 5 2 3 1 6 10 2 9 3 5 4 7 1 8
 

Source

 

分奇数和偶数,随便搞一下

hdu由于没有special judge,无法AC

1 //##################### 2 //Author:fraud 3 //Blog: http://www.cnblogs.com/fraud/ 4 //##################### 5 #include 
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 #include
20 #include
21 #include
22 #include
23 #include
24 #include
25 using namespace std;26 #define XINF INT_MAX27 #define INF 0x3FFFFFFF28 #define MP(X,Y) make_pair(X,Y)29 #define PB(X) push_back(X)30 #define REP(X,N) for(int X=0;X
=L;X--)33 #define CLR(A,X) memset(A,X,sizeof(A))34 #define IT iterator35 typedef long long ll;36 typedef pair
PII;37 typedef vector
VII;38 typedef vector
VI;39 #define MAXN 100001040 int a[MAXN];41 int main()42 {43 int n;44 while(scanf("%d",&n)&&n){45 a[1]=3;46 a[2]=1;47 for(int i=3;i<=n;i++){48 if(i&1)a[i]=i+2;49 else a[i]=i-2;50 }51 if(n&1)a[n]=n-1;52 else{53 a[n]=n-2;54 a[n-1]=n;55 }56 printf("%d",a[1]);57 for(int i=2;i<=n;i++){58 printf(" %d",a[i]);59 }60 printf("\n");61 }62 return 0;63 }
代码君

 

转载于:https://www.cnblogs.com/fraud/p/4354694.html

你可能感兴趣的文章
对闭包的理解
查看>>
练习10-1 使用递归函数计算1到n之和(10 分
查看>>
Oracle MySQL yaSSL 不明细节缓冲区溢出漏洞2
查看>>
windows编程ASCII问题
查看>>
.net webService代理类
查看>>
Code Snippet
查看>>
Node.js Express项目搭建
查看>>
zoj 1232 Adventure of Super Mario
查看>>
1201 网页基础--JavaScript(DOM)
查看>>
组合数学 UVa 11538 Chess Queen
查看>>
oracle job
查看>>
Redis常用命令
查看>>
XML学习笔记(二)-- DTD格式规范
查看>>
IOS开发学习笔记026-UITableView的使用
查看>>
[转载]电脑小绝技
查看>>
windos系统定时执行批处理文件(bat文件)
查看>>
thinkphp如何实现伪静态
查看>>
BZOJ 2243: [SDOI2011]染色( 树链剖分 )
查看>>
BZOJ 1925: [Sdoi2010]地精部落( dp )
查看>>
c++中的string常用函数用法总结!
查看>>