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 ...
随机推荐
- es6新语法系列,查找字符串,模板字符串
一.模板字符串: ES6引入了一种新型的字符串字面量语法,我们称之为模板字符串(template strings).除了使用反撇号字符 ` 代替普通字符串的引号 ' 或 " 外,它们看起来与 ...
- Java中的Validated验证
注意点:在使用@NotBlank时,必须与@Valid配着使用,不然不起作用(出现了很奇怪的现象,我第一次试的时候确实有这情况,但是第二次的时候这情况没了,所以这个说不准) @NotBlank 用在S ...
- C# 实现本地化日志管理
1.新建一个类库解决方案 CommnoLog 2.新建两个文件夹 2.1FileUtil.cs 代码如下 public static class FileUtil { /// <summary ...
- 通过Maven构建打包Spring boot,并将config配置文件提取到jar文件外
如果通过不同的IDE打包,着实会觉得依赖性太大,并且容易出现错误,操作也比较复杂 同时,spring-boot-maven-plugin的使用感觉,相关配置太少,并且无法满足方便部署和运行的需求. 这 ...
- css3的过渡、动画、2D、3D效果
浏览器的内核: 谷歌的内核是:webkit 火狐的内核是:gecko Ie的内核是:trident 欧鹏的内核是:presto 国内浏览器的内核:webkit css3针对同一样式在不同的浏览器的兼容 ...
- Kendo 单页面应用(一)概述
Kendo 单页面应用(一)概述 Kendo 单页面应用(Single-Page Application,缩写为 SPA)定义了一组类用于简化 Web 应用(Rich Client)开发,最常见的单页 ...
- CSS font-family 字体名称一览表
windows常见内置中文字体 字体中文名 字体英文名 宋体 SimSun(浏览器默认) 黑体 SimHei 微软雅 ...
- 工作方法-scrum+番茄工作法
1.产品和开发团队近期的工作分析和安排,使用scrum. 产品的工作:通过product backlog来列出 开发团队近期的工作安排:通过sprint backlog来列出,由个人认领,并估算(优先 ...
- (转)VC得到可用的串口列表
//枚举串口 //参数:bEnablePort,哪个串口有效,bEnablePort[0]表示COM1,bEnablePort[n-1]表示COMn //返回值:有效的串口个数 int EnumAll ...
- Python +selenium之设置元素等待
注:本文转载http://www.cnblogs.com/mengyu/p/6972968.html 当浏览器在加载页面时,页面上的元素可能并不是同时被加载完成,这给元素的定位增加了困难.如果因为在加 ...