Method ringing is used to ring bells in churches, particularly in England. Suppose there are 6 bells that have 6 different pitches. We assign the number 1 to the bell highest in pitch, 2 to the second highest, and so on. When the 6 bells are rung in some order—each of them exactly once—it is called a row. For example, 1, 2, 3, 4, 5, 6 and 6, 3, 2, 4, 1, 5 are two different rows.

An ideal performance contains all possible rows, each played exactly once. Unfortunately, the laws of physics place a limitation on any two consecutive rows; when a bell is rung, it has considerable inertia and the ringer has only a limited ability to accelerate or retard its cycle. Therefore, the position of each bell can change by at most one between two consecutive rows.

In Figure ??, you can see the pattern of a non-ideal performance, where bells only change position by at most one.

Given nn, the number of bells, output an ideal performance. All possible rows must be present exactly once, and the first row should be 1, 2, \cdots , n1,2,⋯,n.

Input Format

The first and only line of input contains an integer nn such that 1 \le n \le 81≤n≤8.

Output Format

Output an ideal sequence of rows, each on a separate line. The first line should contain the row 1, 2, \cdots, n1,2,⋯,n and each two consecutive lines should be at most 11 step away from each other. Each row should occur exactly once in the output.(No extra space at the end of each line)

本题答案不唯一,符合要求的答案均正确

样例输入

2

样例输出

1 2
2 1

题目来源

Nordic Collegiate Programming Contest 2015​

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
int n;
const int N=5e5+;
int a[N][];
int x,y;
void solve()
{
a[][]=;
int s=,end=;
for(int i=;i<=;i++)
{
int len=end;
for(int j=s;j<=end;j++)
{
if((j-s)%)//从左往右
{
for(int k=;k<i;k++)
{
len+=;
for(int l=;l<k;l++)//前面的直接复制下来
{
a[len][l]=a[j][l];
}
a[len][k]=i;//插到a[len][k]
for(int m=k+;m<i;m++)//后面的与J行错一复制下来
{
a[len][m]=a[j][m-];
}
}
}
else//从右到左
{
for(int k=i-;k>=;k--)
{
len+=;
for(int l=;l<k;l++)
{
a[len][l]=a[j][l];
}
a[len][k]=i;
for(int m=k+;m<i;m++)
{
a[len][m]=a[j][m-];
}
} }
}
s=end+;//更新s,end.
end=len;
}
}
int jie(int n)
{
int ans=;
for(int i=;i<=n;i++){
ans*=i;
}
return ans;
}
int main()
{
solve();
scanf("%d",&n);
for(int i=;i<=n-;i++)
{
x+=jie(i);
}
y=x+jie(n)-;
for(int i=x;i<=y;i++)
{
for(int j=;j<n;j++)
{
printf("%d%c",a[i][j],j==n-?'\n':' ');
}
}
return ;
}

Nordic Collegiate Programming Contest 2015​ B. Bell Ringing的更多相关文章

  1. Nordic Collegiate Programming Contest 2015​ G. Goblin Garden Guards

    In an unprecedented turn of events, goblins recently launched an invasion against the Nedewsian city ...

  2. Nordic Collegiate Programming Contest 2015​ E. Entertainment Box

    Ada, Bertrand and Charles often argue over which TV shows to watch, and to avoid some of their fight ...

  3. Nordic Collegiate Programming Contest 2015​ D. Disastrous Downtime

    You're investigating what happened when one of your computer systems recently broke down. So far you ...

  4. Nordic Collegiate Programming Contest 2015​(第七场)

    A:Adjoin the Networks One day your boss explains to you that he has a bunch of computer networks tha ...

  5. (寒假GYM开黑)2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)

    layout: post title: 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) author: &qu ...

  6. German Collegiate Programming Contest 2015 计蒜课

    // Change of Scenery 1 #include <iostream> #include <cstdio> #include <algorithm> ...

  7. Codeforces Gym101572 B.Best Relay Team (2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017))

    2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017) 今日份的训练,题目难度4颗星,心态被打崩了,会的算法太少了,知 ...

  8. 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)- D. Delivery Delays -二分+最短路+枚举

    2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)- D. Delivery Delays -二分+最短路+枚举 ...

  9. 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp

    2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp [P ...

随机推荐

  1. linux替换文件中的某个字符串的命令sed

    sed -i 's/java-7-oracle/java-8-oracle/g' /etc/init.d/tomcat7 上面的命令是将tomcat7中的java-7-oracle替换为java-8- ...

  2. STM32开关总中断

    引用 http://www.amobbs.com/forum.php?mod=viewthread&tid=5397451 在 STM32/Cortex-M3 中是通过改变 CPU 的当前优先 ...

  3. redis启动内存不足

    redis-server.exe redis.windows.conf  --maxheap 2gb

  4. mongodb的投影

    mongodb 投影意思是只选择必要的数据而不是选择一个文件的数据的整个.如果一个文档有5个字段,需要显示只有3个,然后选择其中只有3个字段. find() 方法 MongoDB 的find()方法, ...

  5. window.open()弹出窗口参数说明及居中设置

    window.open()可以弹出一个新的窗口,并且通过参数控制窗口的各项属性. 最基本的弹出窗口代码 window.open('httP://codeo.cn/'); window.open()各参 ...

  6. dedecms会员中心编辑器无法上传图片

    文件:include\dialog\config.php 找到这行代码: $cuserLogin = new userLogin(); 把上面代码下面的这些注释掉: if($cuserLogin-&g ...

  7. SQL 中的group by (转载)

    概述 原始表 简单Group By Group By 和 Order By Group By中Select指定的字段限制 Group By All Group By与聚合函数 Having与Where ...

  8. 打开某exe提示"应用程序无法启动,因为应用程序的并行配置不正确……"的解决方案

    本人在新安装好了的windows server 2008 r2 (64位)上运行“RefilesName V2.0(文件批量改名).exe”,结果提示: 应用程序无法启动,因为应用程序的并行配置不正确 ...

  9. 卓越管理的实践技巧(1)如何进行有效的指导 Guidelines for Effective Coaching

    Guidelines for Effective Coaching 前文卓越管理的秘密(Behind Closed Doors)最后一部分提到了总结的13条卓越管理的实践技巧并列出了所有实践技巧名称的 ...

  10. python_107_ __metaclass__ 元类

    类默认是由 type 类实例化产生,type类中如何实现的创建类?类又是如何创建对象? 答:类中有一个属性 __metaclass__,其用来表示该类由 谁 来实例化创建,所以,我们可以为 __met ...