转载请注明出处: 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

 //#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define XINF INT_MAX
#define INF 0x3FFFFFFF
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
#define MAXN 1000010
int a[MAXN];
int main()
{
int n;
while(scanf("%d",&n)&&n){
a[]=;
a[]=;
for(int i=;i<=n;i++){
if(i&)a[i]=i+;
else a[i]=i-;
}
if(n&)a[n]=n-;
else{
a[n]=n-;
a[n-]=n;
}
printf("%d",a[]);
for(int i=;i<=n;i++){
printf(" %d",a[i]);
}
printf("\n");
}
return ;
}

代码君

uva11630 or hdu2987 Cyclic antimonotonic permutations(构造水题)的更多相关文章

  1. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...

  2. codeforces 22C System Administrator(构造水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud System Administrator Bob got a job as a s ...

  3. Educational Codeforces Round 94 (Rated for Div. 2) A. String Similarity (构造水题)

    题意:给你一个长度为\(2*n-1\)的字符串\(s\),让你构造一个长度为\(n\)的字符串,使得构造的字符串中有相同位置的字符等于\(s[1..n],s[2..n+1],...,s[n,2n-1] ...

  4. hdu 2044:一只小蜜蜂...(水题,斐波那契数列)

    一只小蜜蜂... Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepte ...

  5. hdu 2041:超级楼梯(水题,递归)

    超级楼梯 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...

  6. codeforces Gym 100187L L. Ministry of Truth 水题

    L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  7. POJ 水题(刷题)进阶

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  8. Atcoder 水题选做

    为什么是水题选做呢?因为我只会水题啊 ( 为什么是$Atcoder$呢?因为暑假学长来讲课的时候讲了三件事:不要用洛谷,不要用dev-c++,不要用单步调试.$bzoj$太难了,$Topcoder$整 ...

  9. CF330 C. Purification 认真想后就成水题了

    C. Purification time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. SQL学习笔记——SQL中的数据查询语句汇总

    where条件表达式 --统计函数 Select count(1) from student; --like模糊查询 --统计班上姓张的人数 select count(*) from student ...

  2. DOM之节点|属性

    1.查询文档的一个或多个元素有如下方法 a. 用指定的id属性:(若一个文档中有两个相同的id,只会选择第一个;在低于IE8的IE中,getElementById()对匹配元素的ID不区分大小写,而且 ...

  3. trim()方法去除字符串首尾空格

    trim()方法去除字符串首尾空格 1.原生js                 Function trimStr(str){                         Return str.r ...

  4. JSON基础知识

    1.什么是json •        JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) •        JSON 是轻量级的文本数据交换格式 ...

  5. NPAPI开发常识

    其实,就在几天前,我根本不知道什么是NPAPI插件.因为最近的项目中用到需要在非IE下检测客户端是否安装,最终找到浏览器插件NPAPI. 以下资料来源于网络收集,以此给那些和我一样迷茫的人.本文的目的 ...

  6. LeetCode_Next Permutation

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  7. MVC 自定义错误处理

    1. Application_Error namespace Libaray.Web{ public class MvcApplication : System.Web.HttpApplication ...

  8. HashMap Java Doc

    原文 public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneab ...

  9. UVa133.The Dole Queue

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  10. MBI 跨国网络传销 金字塔诈骗 解密

    马来西亚  反传销博客地址http://combatingillegalpyramidscheme.blogspot.jp/search/label/Mface 需要FQ访问  闽渝警方协作抓获一名公 ...