第六届河南省赛 zzulioj 1486: Card Trick (模拟)nyoj 714
来源:互联网 发布:淘宝女装店铺推广文案 编辑:程序博客网 时间:2024/05/01 16:28
1486: Card Trick
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 60 Solved: 36
SubmitStatusWeb Board
Description
The magician shuffles a small pack of cards, holds it face down and performs the following procedure:
1. The top card is moved to the bottom of the pack. The new top card is dealt face up onto the table. It is the Ace of Spades.
2. Two cards are moved one at a time from the top to the bottom. The next card is dealt face up onto the table. It is the Two of Spades.
3. Three cards are moved one at a time…
4. This goes on until the nth and last card turns out to be the n of Spades.
This impressive trick works if the magician knows how to arrange the cards beforehand (and knows how to give a false shuffle). Your program has to determine the initial order of
the cards for a given number of cards, 1 ≤ n ≤ 13.
Input
On the first line of the input is a single positive integer k, telling the number of test cases to follow. 1 ≤ k ≤ 10 Each case consists of one line containing the integer n. 1 ≤ n ≤ 13
Output
For each test case, output a line with the correct permutation of the values 1 to n, space separated. The first number showing the top card of the pack, etc…
Sample Input
Sample Output
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[15];int vis[15];int main(){int t,n,i,j,k,s;scanf("%d",&t);while(t--){scanf("%d",&n);for(i=0;i<=n;i++)vis[i]=0;i=1;k=1;s=0;while(k<=n){if(vis[i]==0){if(s==k){a[i]=k;k++;s=-1;vis[i]=1;}s++;}i++;if(i>n)i=1;}for(i=1;i<n;i++)printf("%d ",a[i]);printf("%d\n",a[n]);}return 0;}
Source
河南省第六届大学生程序设计竞赛
- 第六届河南省赛 zzulioj 1486: Card Trick (模拟)nyoj 714
- 第六届acm河南省赛——Card Trick 模拟
- 河南省第六届程序设计大赛--Card Trick
- 第六届河南省赛 zzulioj 1481: 异 形 卵 (DP)水 nyoj 709
- 第六届河南省赛 zzulioj 1484: 探 寻 宝 藏 (二维双线DP)nyoj 712
- 第六届河南省赛 zzulioj 1482: 外星人的供给站 (贪心)nyoj 710
- 第六届河南省赛 zzulioj 1488: River Crossing (一维DP)nyoj 716
- 第六届河南省赛 zzulioj 1487: Adjacent Bit Counts (01串DP)nyoj 715
- 河南省第六届大学生程序设计竞赛--Card Trick
- nyoj714 Card Trick(第六届河南省程序设计大赛)
- 河南省第六届大学生程序设计竞赛 F Card Trick
- NYOJ 714 Card Trick
- NYOJ 714 Card Trick
- NYOJ 714 Card Trick
- nyoj 714 Card Trick
- nyoj 714 Card Trick
- NYOJ Card Trick----714
- NYOJ--714--Card Trick
- Unity_2D游戏实例从零讲起(1)——认识游戏引擎与Unity
- 原创《终极网络服务端编程》pdf+配套源码
- 在myeclipse中导入相应的包后,tomcat依然提示找不到包的原因
- jdk实现常见的加密算法
- iOS --- OpenGLES之着色器(shader)的编译、链接及使用
- 第六届河南省赛 zzulioj 1486: Card Trick (模拟)nyoj 714
- JavaScript基础——Ajax与Comet
- uva Fire!
- 数据结构和算法经典100题-第33题
- java环境变量配置
- Android 振动
- 并查集
- 排序算法实例(冒泡法排序、选择法排序、直接插入排序 、希尔法排序、折半插入排序)
- Python模拟HTTPS请求返回HTTP 401 unauthorized错误