Card
Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 471Accepted Submission(s): 294
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 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
Author
elfness@UESTC_Oblivion
题意:一共52个数 输入n left right 表示把从left 到right的数拿出来 拿出来放到数串的最前面 如此重复n边 问最后的串是什么 (n很大)
思路 由于n 很大 貌似应该有规律 这时候可以找一个短点的小串 比如1 2 3 4 5 6 7 8 对这个串进行操作 最后可以发现
把一个串中的 从left 到right 移动 每移动right次 就会还原 故可对n进行%right 后 暴力
#include<stdio.h>
int main()
{
int cas,i,n,left,right,pos,k;
int a[55],change[55];
scanf("%d",&cas);
for(k=1;k<=cas;k++)
{
for(i=1;i<=52;i++)
scanf("%d",&a[i]);
scanf("%d %d %d",&n,&left,&right);
n=n%right;
while(n--)
{
pos=0;
for(i=left;i<=right;i++)
{
change[++pos]=a[i];
}
for(i=1;i<left;i++)
change[++pos]=a[i];
for(i=right+1;i<=52;i++)
change[++pos]=a[i];
for(i=1;i<=52;i++)
a[i]=change[i];
}
printf("Case #%d:",k);
for(i=1;i<=52;i++)
printf(" %d",a[i]);
printf("\n");
}
return 0;
}
分享到:
相关推荐
2017hdu多校联合训练第一场标程及数据
ACM/ICPC 2010年多校联合第十场第九题的解题报告及代码,AC代码有三个,最好的是src
HDU2013暑期多校联合训练第一场0723-解题报告和标程
2014 Multi-University Training Contest 1多校联合赛标程和部分数据。
一个十分简单的程序,能够ac杭电hdu的第2050题,无注释,简单明了
2019 Multi-University Training Contest 4(2019hdu多校第五场数据与标程),欢迎大家下载
此乃2012多校联赛第五场的题目+数据+题解+标程
HDU2000至2099题的题目以及AC代码(含思路) 适合刚刚接触ACM的同学哦~ emmmm凑字
离线OJ题库(HDU ZJU等,部分有答案),需联网。
收集的部分HDOJ杭电ACM题的代码 大牛勿下 全是基础供初级acmer使用
HDU 的ACM 题目,只做了一些简单的,都是用JAVA语言写的
2019 Multi-University Training Contest 4(2019hdu多校第六场数据与标程)
HDU的一题........HDU DP动态规
ACM HDU题目分类,我自己总结的大概只有十来个吧
HDU 动态规划(46道题目
这是HDU acm 其中一部分题的代码,后续代码会继续上传。
我写的hdu上的一些题AC的题的代码 也许你会有用
100道 acm C语言 hdu 解题报告
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
杭电ACMhdu1163