转载请注明出处: 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. mfc EDIT字体颜色

    改变Edit字体颜色: 1.CMyDlg类中添加成员变量: CBrush m_Brush; 2.OnInitDialog中初进行设置: m_brush.CreateSolidBrush(RGB(0,2 ...

  2. 操作html标签之找到标签

    引入 丰富多彩的html标签构成了网页.例如p,div,li,ul,a......…….它们都有自己默认的样式,且各不一样,例如h1标签就比p标签的margin要大一些.我们学习css的目的是为了改变 ...

  3. 如何让你的 footer 总是在浏览器底部无论什么分辨率无论什么浏览器?

    一个可以用的CSS驱动的可粘在底部的Footer 我们曾经都或多或少的试过用CSS来把Footer固定在底部的经理,但是他们总是不能正常的粘在底部,不是吗?可喜的是,痛苦的研究如何让footer粘在底 ...

  4. WordPress页面函数功能代码调用大全

    WordPress模板基本文件 style.css 样式表文件index.php 主页文件single.php 日志单页文件page.php 页面文件archvie.php 分类和日期存档页文件sea ...

  5. python产生随机名字

    用到random.choice(序列) 在一个序列中随机选取一个值 import random as r a1=['张','金','李','王','赵'] a2=['玉','明','龙','芳','军 ...

  6. Ubuntu mysql中文乱码解决

    #vim /etc/mysql/my.cnf 找到[mysqld]添加 character-set-server = utf8 重启mysql #restart mysql mysql> sho ...

  7. 关appid

    https://code.google.com/p/goagent/wiki/InstallGuide 申请appid

  8. gridview两列数据的互换

    如下图所示: GridView绑定数据的时候,若ReName列里面有数据,则显示ReName列里面的数据,如果没有数据,则显示Name列里面的数据.Name和ReName是数据表里面的两个字段< ...

  9. keil or c51 汇编调用c语言函数 容易忽视的问题

    最近,在用keil 写一个小程序时,想实践一下从汇编调用 C语言函数,我们都知道C语言调用汇编函数讨论得较多,但反过来,从汇编中调用C语言的函数未见深入分析:在开始的时候,还是忽视了一个问题,就是对现 ...

  10. Django学习笔记(精简版)

    dos:安装:python setup.py install 环境变量:D:\Python27;D:\Python27\Lib\site-packages\django\bin; 转到创建的目录:dj ...