hdu_4350_数组模拟_函数调用数组
来源:互联网 发布:淘宝销量怎么查看 编辑:程序博客网 时间:2024/06/07 03:29
Card
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 before every number.
Sample Input
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
Sample Output
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
Source
2012 Multi-University Training Contest 6
题意:
给你52个不同的数,将从L–R的数移到52个数的开头,(包括L,R)重复操作n次,输出n次操作后的52个数;
思路:
找循环节,先模拟找到循环节,一切都出来,
#include<iostream>#include<cstdio>#include<map>#include<cstring>#include<algorithm>#include<cmath>typedef long long ll;using namespace std;int n,l,r;void fun(int arr[]){ int a[111],i; for(i=1;i<=52;i++) a[i]=arr[i]; int len=r-l+1; int tmp=l; for(i=1;i<1+len;i++) arr[i]=a[tmp++]; tmp=1; for(i=1+len;i<=r;i++) arr[i]=a[tmp++];}bool same(int tarr[],int arr[]){ for(int i=1;i<=52;i++) if(tarr[i]!=arr[i]) return false; return true;}int main(){ int t,i,j,arr[66],tarr[66]; while(cin>>t) { for(int c=1; c<=t; c++) { for(i=1; i<=52; i++) { scanf("%d",arr+i); tarr[i]=arr[i]; } scanf("%d%d%d",&n,&l,&r); printf("Case #%d:",c); int cnt=0; while(1) { cnt++; fun(arr); if(same(tarr,arr)) break; } int tmp=n%cnt; // cout<<tmp<<endl; for(i=0; i<tmp; i++) fun(tarr); for(i=1; i<=52; i++) printf(" %d",tarr[i]); puts(""); } } return 0;}
- hdu_4350_数组模拟_函数调用数组
- []数组_函数调用数组 、指针数组、结构体数组
- 26_数组函数的调用
- 三:数组_其它数组函数
- 02_数组与函数
- hdu_1285_拓扑排序入门_数组模拟_队列优化
- 指针与函数_函数指针数组
- 026 数组函数的调用
- 调用函数使用数组排序
- JS调用函数传递数组
- PHP操作 二维数组模拟mysql函数
- 黑马程序员_语句 函数 数组
- 黑马程序员_函数和数组
- 黑马程序员_函数和数组
- 黑马程序员_java基础_函数&数组
- 黑马程序员_函数与数组
- 关于函数_稀疏数组的用法
- C语言_函数指针数组指针
- 安装虚拟机总结
- Java多线程
- 23种设计模式全解析
- 数据库的索引原理
- poj-3041 Asteroids
- hdu_4350_数组模拟_函数调用数组
- Oracle 11G RAC:生产环境下架构
- 【deep learnign】关于 epoch、 iteration和batchsize
- 怎么设置原理图导入到pcb中的默认字体类型(大小,字体)?
- 【C#基础知识】——初识委托(delegate)
- 静态变量和成员变量的区别
- 【算法学习】求两数组求差数(Java,三重境界)
- IntelliJ IDEA+SpringBoot用JDBC做一个小型的javaWeb程序
- HashMap和Hashtable的区别