nyoj 714 Card Trick
2015-04-03 18:19
260 查看
Card Trick
时间限制:1000 ms | 内存限制:65535 KB难度:3
描述
The magician shuffles a small pack of cards, holds it face down and performs the following procedure:
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.
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.
Three cards are moved one at a time…
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.
输入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输出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…样例输入
2
4
5
样例输出
2 1 4 3
3 1 4 5 2
比较简单,n值最大才13.
#include<stdio.h> int a[15]; int main() { int t,n,i,j,m,k; int cishu; scanf("%d",&t); while(t--) { scanf("%d",&n); //最大的两个数顺序先找出 if((n-1)&1) { a =n-1; a[n-1]=n; } else { a =n; a[n-1]=n-1; } //找剩余的 for(i=n-2;i>=1;i--) { a[i]=i; cishu=i; while(cishu--) { k=a ;//保存最后一位的值 for(j=n;j>=i-1;j--) { a[j]=a[j-1]; } a[i]=k;//赋值第一位 } } for(i=1;i<=n;i++) { if(i>1) printf(" "); printf("%d",a[i]); } printf("\n"); } return 0; }
[/code]
相关文章推荐
- 第六届河南省赛 zzulioj 1486: Card Trick (模拟)nyoj 714
- NYOJ714-Card Trick
- NYOJ_714_Card Trick【队列】
- NYOJ--714--Card Trick
- poj 3032 nyoj 714 Card Trick
- nyoj714 Card Trick(第六届河南省程序设计大赛)
- NYOJ714 Card Trick 【队列模拟】
- NYOJ 714 Card Trick(队列queue)
- NYOJ 714 Card Trick
- nyoj 714 Card Trick
- 南阳理工OJ_题目714 Card Trick
- nyoj 714 打牌的技巧(队列)
- NYOJ741 Card Trick
- nyoj 714 第六届河南省大学生程序设计竞赛F
- 南洋理工 714 Card Trick
- 练习场 题目714 Card Trick
- 714 Card Trick
- NYOJ 558 一二三
- 渣渣ACM日记——1160-不能被整除的数(NYOJ)
- NYOJ 21 三个水杯(BFS)