码迷,mamicode.com
首页 > 其他好文 > 详细

uva11630 or hdu2987 Cyclic antimonotonic permutations(构造水题)

时间:2015-03-20 23:29:20      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

转载请注明出处: http://www.cnblogs.com/fraud/           ——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 pi-1, pi, pi+1 (1 < i < n), pi 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 pi as a pointer from i to pi, 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 ≤ 106), 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 <iostream>
 6 #include <sstream>
 7 #include <ios>
 8 #include <iomanip>
 9 #include <functional>
10 #include <algorithm>
11 #include <vector>
12 #include <string>
13 #include <list>
14 #include <queue>
15 #include <deque>
16 #include <stack>
17 #include <set>
18 #include <map>
19 #include <cstdio>
20 #include <cstdlib>
21 #include <cmath>
22 #include <cstring>
23 #include <climits>
24 #include <cctype>
25 using namespace std;
26 #define XINF INT_MAX
27 #define INF 0x3FFFFFFF
28 #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<N;X++)
31 #define REP2(X,L,R) for(int X=L;X<=R;X++)
32 #define DEP(X,R,L) for(int X=R;X>=L;X--)
33 #define CLR(A,X) memset(A,X,sizeof(A))
34 #define IT iterator
35 typedef long long ll;
36 typedef pair<int,int> PII;
37 typedef vector<PII> VII;
38 typedef vector<int> VI;
39 #define MAXN 1000010
40 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 }
代码君

 

uva11630 or hdu2987 Cyclic antimonotonic permutations(构造水题)

标签:

原文地址:http://www.cnblogs.com/fraud/p/4354694.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!