根据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. poj 2762 tarjan缩点+拓扑序

    2013-09-08 10:00 var m, n :longint; t :longint; f, last :..] of longint; pre, other :..] of longint; ...

  2. 你自认为理解了JavaScript?【转】

    第一题 if (!("a" in window)) { var a = 1; } alert(a); 第二题 var a = 1, b = function a(x) { x &a ...

  3. E题hdu 1425 sort

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1425 sort Time Limit: 6000/1000 MS (Java/Others)    M ...

  4. hdu 1233 还是畅通工程 (最小生成树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1233 还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    ...

  5. Windows下基于python3使用word2vec训练中文维基百科语料(三)

    对前两篇获取到的词向量模型进行使用: 代码如下: import gensim model = gensim.models.Word2Vec.load('wiki.zh.text.model') fla ...

  6. mouseover/mouseenter/mouseout/mouseleave的区别

    mouseover:鼠标指针穿过被选元素或其子元素,均会触发事件 mouseenter:鼠标指针穿过被选元素时才触发事件 mouseout:鼠标指针离开被选元素或其子元素则触发事件 mouseleav ...

  7. node遇到的一些坑,npm无反应,cordova安装以后显示不是内部或外部命令

    1.输入npm -v 以后一直无反应 C:\Users\用户名 目录下找到 .npmrc文件,删除以后,执行npm -v顺利显示版本号 2.安装cordova以后一直报错,不是内部或外部命令也不是可运 ...

  8. metasploit后门维持技术

    在meterpreter中执行:run metsvc -A 如此以后便会自动在服务器当中多生成一个meterpreter的服务,并且是开机自动启动.所以二次如果要利用直接: use exploit/m ...

  9. MSF爆破MSSQL

    show options: msf auxiliary(scanner/mssql/mssql_login) > show options Module options (auxiliary/s ...

  10. 微信支付:curl 出错,错误码: 60

    在测试微信支付 - 模式二 - 扫码支付时,遇到如下错误: curl出错,错误码:60 这是因为在 WxPay.Api.php 文件中做了严格的 ssl 证书校验: curl_setopt($ch,C ...