sdibt 3148 To help that magician
来源:互联网 发布:优化探究答案必修一 编辑:程序博客网 时间:2024/05/18 01:47
链接:sdibt 3148
Description
牛谦一直想做个魔术师,最近因为一个叫刘谦的越来越出名,他就更耐不住寂寞了,他决定开始学习魔术。
他学得第一个魔术是这样的。给你n张牌,顺序编号为1~n,现在要重新排列牌的顺序,使他满足下面的表演:
将第一张拿到牌底后,翻开现在的第一张,牌的点数是1,并丢弃这张牌,再把第一张牌放到牌底,翻开如今的第一张,点数是2,丢弃这张牌。。如此重复,每次翻开的点数为上一次加一,直到n为止。但是牛谦毕竟不是刘谦= =他不知道如何安排牌的顺序才能实现这样的表演。你能帮助他吗?
Input
不断输入一个n,直到文件末。(1=<n<=100)
Output
输出能实现此表演的牌的序列
Sample Input
32
Sample Output
2 1 32 1
1.找规律
#include<stdio.h>#include<string.h>int main(){ int a[101],i,j,n,t; while(scanf("%d",&n)!=EOF){ memset(a,0,sizeof(a)); j=1; for(i=1;i<=n;i++){ t=0; for(;;j++){ if(j>n) j=1; if(a[j]==0) t++; if((i<n&&t==2)||(i==n&&t==1)) break; } a[j]=i; } for(i=1;i<n;i++) printf("%d ",a[i]); printf("%d\n",a[n]); } return 0;}
2.反模拟:将原过程逆过来,原先现将一张牌放到牌底,再翻开一张,以这样的过程依次得到1~n,现在反过来,先翻一张,再将底牌移到牌顶,这样依次得到的是n~1
#include<cstdio>#include<vector>using namespace std;int main(){ int n,m,j; vector<int> s; vector<int>::iterator i; while(scanf("%d",&n)!=EOF){ s.clear(); s.push_back(n); for(j=n-1;j>=1;j--){ i=s.begin(); s.insert(i,j); m=s.back(); s.pop_back(); i=s.begin(); s.insert(i,m); } for(i=s.begin();i<s.end()-1;i++) printf("%d ",*i); printf("%d\n",*i); } return 0;}
0 0
- sdibt 3148 To help that magician
- Ten PHP Best Practices Tips that can Help You to Get a Job
- PLUGINS that HELP YOU WORKING WITH ECLIPSE
- help to understand continuation
- Help to memory sth.
- sdibt 1012
- ComponentOne Doc-To-Help 2009
- Use Power to Help people
- Please help to Unix-Center
- The 10 Technologies that Will Help You Stay Employed
- Tools that can help developer debugging web services
- The 10 Technologies that Will Help You Stay Employed
- Personal Branding: 8 Tips That Will Help You Stand Out
- 5 Simple Things That Can Help Change Your Attitude
- 5 Simple Things That Can Help Change Your Attitude
- Advice that can help you succeed on Campus
- How to help people switch to Linux?
- How to add help to Apex pages
- 求二叉树中节点的最大距离
- windows8.1 安装vs2010后 vs2010显示遇到位置问题关闭的问题解决办法
- java自学之路
- 二分图匹配详解
- Hadoop ecosystem
- sdibt 3148 To help that magician
- Linux中的Apache的编译安装和配置
- linux :Java SE Development Kit 7u5
- 解决ubuntu使用笔记本自带电池后鼠标断电或间歇性失灵
- 我的异常之Cannot assign requested address:jvm_bind
- 局域网中解决网络穿越(实现打洞)
- 关于sqlplus的show parameter问题
- 一个简单的http服务器的实现
- 软件开发具体流程