Reprint Please specify source: 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 Descriptiona permutation is a sequence of integers which contains each integer from 1 to n exactly once. In this problem we is looking for permutations with special properties:
1. antimonotonic:for 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's, 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.
Inputthe input file contains several test cases. Each test case is consists of a line containing an integer n, (3≤n≤106), the number of integers in the permutation. Input is terminated by n=0.
Outputfor each test case, print a permutation of the integers 1 to n which are both antimonotonic and cyclic. In case there is multiple solutions, you could print any one. Separate all integers by whitespace characters.
Sample Input35100
Sample OUTPUT3 1 24 5 2 3 16 10 2 9 3 5 4 7 1 8
source2009/2010 ULM Local Contest
Odd and even, whatever.
HDU because there is no special judge, cannot AC
1 //#####################2 //Author:fraud3 //Blog:http://www.cnblogs.com/fraud/4 //#####################5#include <iostream>6#include <sstream>7#include <ios>8#include <iomanip>9#include <functional>Ten#include <algorithm> One#include <vector> A#include <string> -#include <list> -#include <queue> the#include <deque> -#include <stack> -#include <Set> -#include <map> +#include <cstdio> -#include <cstdlib> +#include <cmath> A#include <cstring> at#include <climits> -#include <cctype> - using namespacestd; - #defineXinf Int_max - #defineINF 0X3FFFFFFF - #defineMP (x, y) make_pair (x, y) in #definePB (x) push_back (x) - #defineREP (x,n) for (int x=0; x<n; X + +) to #defineREP2 (X,L,R) for (int x=l; x<=r; X + +) + #defineDEP (x,r,l) for (int x=r; x>=l; x--) - #defineCLR (a,x) memset (a,x,sizeof (A)) the #defineIT iterator *typedefLong Longll; $typedef pair<int,int>PII;Panax Notoginsengtypedef vector<pii>VII; -typedef vector<int>VI; the #defineMAXN 1000010 + intA[MAXN]; A intMain () the { + intN; - while(SCANF ("%d", &n) &&N) { $a[1]=3; $a[2]=1; - for(intI=3; i<=n;i++){ - if(i&1) a[i]=i+2; the Elsea[i]=i-2; - }Wuyi if(n&1) a[n]=n-1; the Else{ -a[n]=n-2; Wua[n-1]=N; - } Aboutprintf"%d", a[1]); $ for(intI=2; i<=n;i++){ -printf"%d", A[i]); - } -printf"\ n"); A } + return 0; the}
code June
uva11630 or hdu2987 Cyclic antimonotonic permutations (tectonic water problem)