根据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;
}

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

  1. 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 ...

  2. 排序构造 GYM 101149 F - The Weakest Sith

    题目链接:http://codeforces.com/gym/101149/my 题目大意:给你n个人,他们有成绩a,b,c.一个人如果两门课比另外一个人高,那么这个人就比那个人厉害.问,是否存在一个 ...

  3. 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 ...

  4. Codeforces Gym 100187K K. Perpetuum Mobile 构造

    K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

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

    Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  6. Codeforces Gym 100531I Instruction 构造

    Problem I. Instruction 题目连接: http://codeforces.com/gym/100531/attachments Description Ingrid is a he ...

  7. Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造

    Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...

  8. Codeforces Gym 100425H H - Football Bets 构造

    H - Football BetsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  9. Tree Reconstruction Gym - 101911G(构造)

    ---恢复内容开始--- Monocarp has drawn a tree (an undirected connected acyclic graph) and then has given ea ...

随机推荐

  1. bzoj 1084 DP

    首先对于m==1的情况非常容易处理(其实这儿因为边界我错了好久...),直接DP就好了,设f[i][k]为这个矩阵前i个选k个矩阵的最大和,那么f[i][k]=max(f[j][k-1]+sum[j+ ...

  2. CPU架构及并发编程基础(一)

    一.intel cpu发展计划tick-tock Tick-Tock是Intel发展微处理器芯片设计制造业务的一种战略模式.Intel指出,每一次处理器微架构的更新和每一次芯片制程的更新遵循“Tick ...

  3. mysql中的时间year/date/time/datetime

    year: mysql> create table y(y year); Query OK, 0 rows affected (0.03 sec) mysql> desc y; +---- ...

  4. js获取链接参数

    var url = location.search; var Request = new Object(); if(url.indexOf("?")!=-1){ var str = ...

  5. centos 引导盘

    # grub.conf generated by anaconda## Note that you do not have to rerun grub after making changes to ...

  6. C#ActiveX控件开发

    1.新建项目,选择C#,选择.NET Framework2.0,新建一个Windows窗体控件库项目,命名为ActiveXDemo; 2.右击ActiveXDem项目,选择属性——应用程序——程序集信 ...

  7. LCT 文档

    file:///C:/Users/Frank/Downloads/QTREE%E8%A7%A3%E6%B3%95%E7%9A%84%E4%B8%80%E4%BA%9B%E7%A0%94%E7%A9%B ...

  8. linux命令(37):locate命令

    1.命令格式: Locate [选择参数] [样式] 2.命令功能: locate命令可以在搜寻数据库时快速找到档案,数据库由updatedb程序来更新,updatedb是由cron daemon周期 ...

  9. Django Ajax学习二之csrf跨站请求伪造

    方式1 $.ajaxSetup({ data: {csrfmiddlewaretoken: '{{ csrf_token }}' }, }); 方式2 # html文件from表单中<form& ...

  10. 关于微信获取access_token接口,返回值为-1000的问题

    今天打算获取token来,来修改公众号的菜单,结果像往常一样输入了appid 和 secret ,结果没有返回access_token,而是返回了一个-1000,并提示 "未知返回状态&qu ...