第六届acm河南省赛——Card Trick 模拟
来源:互联网 发布:garch模型 python 编辑:程序博客网 时间:2024/05/01 10:16
题目链接:Card Trick
Card Trick
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 62 Solved: 38
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
HINT
题目分析:题干里夹杂一堆生僻词(也可能是我英语渣),反正题意晦涩难懂,但是弄明白题意后就好做多了。可以设立一个二维循环数组来模拟每次操作的过程,注意要避开要扔掉的那张牌并记录其位置,把对应的数字放到那个位置里,先把表打出来,然后每次查询即可。
注意不要忘了取模。
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int ans[14][20];int buf[2][20];void init(){ ans[1][0]=1; for(int i=2;i<=13;i++) { memset(buf,0,sizeof(buf)); for(int j=0;j<i;j++) buf[0][j]=j; int num=i,tims=1,pos=1,temp=0; while(num>0) { for(int j=0;j<num-1;j++) { buf[temp^1][j]=buf[temp][(j+tims+1)%num]; } int s=buf[temp][tims%num]; ans[i][s]=pos++; temp=temp^1; num--; tims++; } }}int main(){ init(); int T; cin>>T; while(T--) { int n; cin>>n; for(int i=0;i<n-1;i++) { cout<<ans[n][i]<<" "; } cout<<ans[n][n-1]<<endl; }}
- 第六届acm河南省赛——Card Trick 模拟
- 第六届河南省赛 zzulioj 1486: Card Trick (模拟)nyoj 714
- 河南省第六届程序设计大赛--Card Trick
- 第六届ACM省赛 Card Trick
- 河南省第六届大学生程序设计竞赛--Card Trick
- nyoj714 Card Trick(第六届河南省程序设计大赛)
- 河南省第六届大学生程序设计竞赛 F Card Trick
- 河南第六届ACM省赛(Card Trick)
- 第六届acm河南省赛——Adjacent Bit Counts
- 河南省第六届ACM River Crossing
- POJ-3032 Card Trick【模拟】
- NYOJ714 Card Trick 【队列模拟】
- ACM篇:POJ 2200 --A Card Trick
- SPOJ 1108. Card Trick 模拟题
- poj 2200 A Card Trick(模拟)
- 河南省第六届ACM大学生程序设计竞赛 排行榜
- 河南省第六届acm省赛 异 形 卵(暴力)
- 第六届河南省ACM大赛 B外星人的供给站
- JAVA——利用wait和notify实现生产者和消费者
- Hibernate的环境搭建
- 浏览器兼容性 Edge需要另外的判断
- 设计模式之禅-单一职责原则
- JVM知识点梳理
- 第六届acm河南省赛——Card Trick 模拟
- IE如何禁止某个特定网站的Cookie
- 第106讲: Spark Streaming电商广告点击综合案例黑名单过滤实现
- 做技术必须沉得住气
- 算法的正确打开方式
- ural 1152 搜索或状压
- Java aidl分析
- nyoj 1242 Interference Signal 河南省ACM2015年省赛G题
- C++ 流操作(531 --)