Nordic Collegiate Programming Contest 2015 B. Bell Ringing
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的更多相关文章
- Nordic Collegiate Programming Contest 2015 G. Goblin Garden Guards
In an unprecedented turn of events, goblins recently launched an invasion against the Nedewsian city ...
- 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 ...
- 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 ...
- 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 ...
- (寒假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 ...
- German Collegiate Programming Contest 2015 计蒜课
// Change of Scenery 1 #include <iostream> #include <cstdio> #include <algorithm> ...
- 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颗星,心态被打崩了,会的算法太少了,知 ...
- 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 -二分+最短路+枚举 ...
- 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 ...
随机推荐
- 061 Rotate List 旋转链表
给定一个链表,将链表向右旋转 k 个位置,其中 k 是非负数.示例:给定 1->2->3->4->5->NULL 且 k = 2,返回 4->5->1-> ...
- BeanCopier使用说明
BeanCopier从名字可以看出了,是一个快捷的bean类复制工具类. 一 如何使用,我就直接丢代码了 public class BeanCopierTest { static SimpleDate ...
- EF+mvc+mysql
这个真是一个大坑啊.TM折腾了一下午终于弄好了.赶紧记录下来分享给大家,免得有和我一样一直配置不成功的又折腾半天….1.安装MySQL for Visual Studio这个直接在mysql官网下载并 ...
- 数据库操作是sql的操作1
项目过来以后, 查 先肯定是做UI , 1.在UI层先加载 2数据来源在dal层, 3再到model层,得到属性 public int MId { get; set; } public string ...
- js中Object.defineProperty()和defineProperties()
在介绍js中Object.defineProperty()和defineProperties()之前,我们了解下js中对象两种属性的类型:数据属性和访问器属性. 数据属性 数据属性包含一个数据的位置, ...
- Java面向对象(接口、多态)
面向对象 今日内容介绍 u 接口 u 多态 第1章 接口 1.1 接口概念 接口是功能的集合,同样可看做是一种数据类型,是比抽象类更为抽象的”类”. 接口只描述所应该具备的方法,并没有具体实现,具体的 ...
- java校验maven下载的jar文件
有时候maven真的很坑! 有时候提示invalid LOC header (bad signat signature), 但又有时候什么都不提示,工程报错,情况有肯多中,不知道大家遇到过几种诡异的. ...
- Outlook 客户端无法通过 MAPI over HTTP协议 连接
随着Exchange 版本更新升级,是否进行验证客户端建立MapiHttp连接所需的服务器设置已正确配置.即使服务器,负载均衡器和反向代理的所有设置都正确,您可能会遇到连接到Exchange Serv ...
- 使用Timer组件制作计时器
实现效果: 知识运用: Timer组件的interval属性 //获取或设置Timer组件Tick事件发生的时间间隔 public int Interval {get;set} NumericUpDo ...
- c#和Java中的接口
使用场景: 在c#和Java中: 1.接口可以实现“多继承”(多实现),一个类只能继承自一个父类,但是可以实现多个接口. 2.接口解决了不同类型之间的多态问题,比如鱼与船不是同一类型,但是都能在水里“ ...