【构造】Gym - 100781B - Bell Ringing

根据n-1推n的情况,让n从每一个的最右走到最左,再从下一个最左走到最右,如此往复即可。

#include<cstdio>
using namespace std;
int n,a[50000][10],e,b[50000][10],e2;
int main(){
	scanf("%d",&n);
	if(n==1){
		puts("1");
		return 0;
	}
	e=1;
	a[1][1]=1;
	for(int i=2;i<=n;++i){
		e2=0;
		for(int j=1;j<=e;++j){
			if(j%2==1){
				for(int k=i;k>=1;--k){
					int cnt=0;
					++e2;
					if(k==1){
						++cnt;
						b[e2][cnt]=i;
						if(i==n)printf("%d%c",b[e2][cnt],cnt==i?‘\n‘:‘ ‘);
					}
					for(int l=1;l<i;++l){
						++cnt;
						b[e2][cnt]=a[j][l];
						if(i==n)printf("%d%c",b[e2][cnt],cnt==i?‘\n‘:‘ ‘);
						if(l==k-1){
							++cnt;
							b[e2][cnt]=i;
							if(i==n)printf("%d%c",b[e2][cnt],cnt==i?‘\n‘:‘ ‘);
						}
					}
				}
			}
			else{
				for(int k=1;k<=i;++k){
					int cnt=0;
					++e2;
					if(k==1){
						++cnt;
						b[e2][cnt]=i;
						if(i==n)printf("%d%c",b[e2][cnt],cnt==i?‘\n‘:‘ ‘);
					}
					for(int l=1;l<i;++l){
						++cnt;
						b[e2][cnt]=a[j][l];
						if(i==n)printf("%d%c",b[e2][cnt],cnt==i?‘\n‘:‘ ‘);
						if(l==k-1){
							++cnt;
							b[e2][cnt]=i;
							if(i==n)printf("%d%c",b[e2][cnt],cnt==i?‘\n‘:‘ ‘);
						}
					}
				}
			}
		}
		e=e2;
		for(int j=1;j<=e2;++j){
			for(int k=1;k<=i;++k){
				a[j][k]=b[j][k];
			}
		}
	}
	return 0;
}
时间: 2024-08-07 21:19:39

【构造】Gym - 100781B - Bell Ringing的相关文章

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

Codeforces Gym 100187K K. Perpetuum Mobile 构造

K. Perpetuum Mobile Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/K Description The world famous scientist Innokentiy almost finished the creation of perpetuum mobile. Its main part is the energy generator whic

Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉

Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description Andrew is having a hard time preparing his 239-th contest for Petrozavodsk. This time the solution to the problem is based on Di

Gym - 100801H Hash Code Hacker (构造)

题意:求 n 个哈希值相同的串. 析:直接构造,通过取模来查找相同的串. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring>

UVaLive 6588 &amp;&amp; Gym 100299I (贪心+构造)

题意:给定一个序列,让你经过不超过9的6次方次操作,变成一个有序的,操作只有在一个连续区间,交换前一半和后一半. 析:这是一个构造题,我们可以对第 i 个位置找 i 在哪,假设 i  在pos 位置,那么如果 (pos-i)*2+i-1 <= n,那么可以操作一次换过来, 如果不行再换一种,如果他们之间元素是偶数,那么交换 i - pos,如果是奇数,交换 i - pos+1,然后再经过一次就可以换到指定位置. 代码如下: #pragma comment(linker, "/STACK:1

Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造

Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Andrea is a famous science fiction writer, who runs masterclasses for her beloved readers. The most popular one is the

Gym 100851J Jump 构造

Problem J. JumpInput ?le: standard inputOutput ?le: standard outputConsider a toy interactive problem OneMax which is de?ned as follows. You know an integer n andthere is a hidden bit string S of length n. The only thing you may do is to present the

GYM 101173 K.Key Knocking(构造)

原题链接 参考自 问题描述:一个长度为3*n的01串,每次可以翻转连续的两个字符,要求至多翻转n次使得这个3*n的串至少有2*n个连续的段且相邻两端不一样(就是连续的0算一段,然后连续的1,…) 解法:每三个一组,只要能把每组分成两段而且和前面的不连着最后段数一定不小于2*n,例如前一个是1(0同理),当前组只有八种情况(冒号前表示操作前状态,冒号后表示操作后的状态): 000:011 001:001 010:010 011:011 100:010 101:101 110:101 111:001

恶补---bell数

定义 bell数即一个集合划分的数目 示例 前几项的bell数列为 1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975 ,... 求值方法 1.bell数适合递推公式 2.每个贝尔数都是"第二类Stirling数"的和 3.用一下方法可以构造一个bell三角形(Aitken阵列或Peirce三角形) 1)第一行第一列是1 2)对于n>1,第n行第一列等于上一行的最后一个数 3)对于n>1,m>1,第n行第m列=第n行第m