[置顶] Card
2012-08-10 16:29
351 查看
Card
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 664 Accepted Submission(s): 322
Problem Description
Bearchild is playing a card game with himself. But first of all, he needs to shuffle the cards. His strategy is very simple: After putting all the cards into a single stack, he takes out some cards in the middle, from the L-th to the R-th when counting from
top to bottom, inclusive, and puts them on the top. He repeats this action again and again for N times, and then he regards his cards as shuffled.
Given L,R and N, and the initial card stack, can you tell us what will the card stack be like after getting shuffled?
Input
First line contains an integer T(1 <= T <= 1000), which is the test cases.
For each test case, first line contains 52 numbers(all numbers are distinct and between 1 and 52), which is the card number of the stack, from top to bottom.
Then comes three numbers, they are N, L and R as described. (0<=N<=109, 1<=L<=R<=52)
Output
For each test case, output "Case #X:", X is the test number, followed by 52 numbers, which is the card number from the top to bottom.Note that you should output one and only one blank befor every number.
SampleInput
1 13 2 10 50 1 28 37 32 30 46 19 47 33 41 24 52 27 42 49 18 9 48 23 35 31 8 7 12 6 5 3 22 43 36 51 40 26 4 44 17 39 38 15 14 25 16 29 20 21 45 11 34 902908328 38 50
SampleOutput
Case #1: 26 4 44 17 39 38 15 14 25 16 29 20 21 45 13 2 10 50 1 28 37 32 30 46 19 47 33 41 24 52 27 42 49 18 9 48 23 35 31 8 7 12 6 5 3 22 43 36 51 40 11 34
Author
elfness@UESTC_Oblivion
AC CODE(15MS)
#include <iostream> #include <cstdio> using namespace std; int main() { int T, ca = 1, N, n, l, r, a, i, cnt; int card1[53], card2[53]; //分别记录card的当前状态和上一状态 scanf("%d", &T); while(T--) { for(i = 1; i < 53; i++) scanf("%d", &card1[i]); scanf("%d%d%d", &n, &l, &r); a = card1[1]; //记录首元素 N = n; //备份n //cnt记录周期的长度 for(i = 1, cnt = 1; n--; i = -i, cnt++) { int j, k; if(i > 0) { for(j = 1, k = l; k <= r; j++, k++) card2[j] = card1[k]; for(k = 1; k < l; k++, j++) card2[j] = card1[k]; for(k = r+1; k < 53; k++, j++) card2[j] = card1[k]; if(a == card2[1]) n = N % cnt; //找到周期 } else { for(j = 1, k = l; k <= r; j++, k++) card1[j] = card2[l+j-1]; for(k = 1; k < l; k++, j++) card1[j] = card2[k]; for(k = r+1; k < 53; k++, j++) card1[j] = card2[k]; if(a == card1[1]) n = N % cnt; //找到周期 } } //输出 printf("Case #%d:", ca++); if(i > 0) { for(int j = 1; j < 52; j++) printf(" %d", card1[j]); printf(" %d\n", card1[52]); } else { for(int j = 1; j < 52; j++) printf(" %d", card2[j]); printf(" %d\n", card2[52]); } } return 0; }
相关文章推荐
- [置顶] 通配符匹配(Wildcard Matching)与正则表达式匹配(Regular Expression Matching)解法解析
- [置顶] 通配符匹配(Wildcard Matching)与正则表达式匹配(Regular Expression Matching)解法解析
- [置顶] Android开发之CardView的使用
- [置顶] Android使用RecyclerView和CardView,实现知乎日报精致布局
- [置顶] 通配符匹配(Wildcard Matching)与正则表达式匹配(Regular Expression Matching)解法解析
- [置顶] 通配符匹配(Wildcard Matching)与正则表达式匹配(Regular Expression Matching)解法解析
- [置顶] Hive安装与配置
- [置顶] (巨坑)长期经验总结
- [置顶] 学习日志
- [置顶] MxNet使用总览
- [置顶] spi设备/硬件spi
- android获取SDCard中照片并按照时间顺序显示
- [置顶] github上的给力工具---条形码生成JsBarcode
- [置顶] 使用Tomcat+腾讯云主机把你的项目发布到外网上
- [置顶] PHP根据经纬度获取地址信息
- [置顶] node上传文件到七牛云
- [置顶] Android 操作SQLite数据库(初步)-在程序中删除数据库
- [置顶] Android 蓝牙开发(二)Ble 开发(android4.3)
- [置顶] 【KMP/KMP扩展】目录
- [置顶] Linux安装tomcat部署java web项目