打表找规律,比赛应付了一下,其实还可以把内存再优化一半掉,下面的0都是手动填充的,可以优化掉

题意:

T个测试数据

下面52个数字表示 从栈顶到栈底的52个数

n l r表示 从栈顶下数 [l,r] 这个区间的数都放到栈顶

这样n次操作后的结果

这里可以猜想 n 操作应该是有重复的,也就是取模

n%MOD , MOD是个关于 l ,r 的表达式

省时间就直接打表了

#include<stdio.h>
int s1[53],s2[53],st2;
void outstack(int l,int r){
st2=1;
int i;
for(i=l;i<=r;i++)
s2[st2++]=s1[i];
for(i=l;i+r-l+1<=52;i++)
s1[i]=s1[i+r-l+1]; st2=1;
for(;i<=52;i++)
s1[i]=s2[st2++];
} int mod[52][52]={52,26,52,13,52,26,52,13,52,26,52,13,4,26,52,13,52,26,52,13,52,26,52,13,52,2,52,13,52,26,52,13,52,26,52,13,52,26,4,13,52,26,52,13,52,26,52,13,52,26,52,1,0,51,51,17,51,51,17,51,51,17,51,51,17,51,51,17,51,3,17,51,51,17,51,51,17,51,51,17,51,51,17,51,51,17,3,51,17,51,51,17,51,51,17,51,51,17,51,51,17,51,51,1,0,0,50,25,50,25,10,25,50,25,50,5,50,25,50,25,10,25,50,25,50,5,50,25,50,25,2,25,50,25,50,5,50,25,50,25,10,25,50,25,50,5,50,25,50,25,10,25,50,25,50,1,0,0,0,49,49,49,49,49,49,7,49,49,49,49,49,49,7,49,49,49,49,49,49,7,49,49,49,49,49,49,7,49,49,49,49,49,49,7,49,49,49,49,49,49,7,49,49,49,49,49,49,1,0,0,0,0,48,24,16,12,48,8,48,6,16,24,48,4,48,24,16,3,48,8,48,12,16,24,48,2,48,24,16,12,48,8,48,3,16,24,48,4,48,24,16,6,48,8,48,12,16,24,48,1,0,0,0,0,0,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,1,0,0,0,0,0,0,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,2,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,1,0,0,0,0,0,0,0,45,45,15,45,9,15,45,45,5,9,45,15,45,45,3,45,45,5,45,9,15,45,45,15,9,45,5,45,45,3,45,45,15,45,9,5,45,45,15,9,45,15,45,45,1,0,0,0,0,0,0,0,0,44,22,44,11,44,22,44,11,44,22,4,11,44,22,44,11,44,22,44,11,44,2,44,11,44,22,44,11,44,22,44,11,4,22,44,11,44,22,44,11,44,22,44,1,0,0,0,0,0,0,0,0,0,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,1,0,0,0,0,0,0,0,0,0,0,42,21,14,21,42,7,6,21,14,21,42,7,42,3,14,21,42,7,42,21,2,21,42,7,42,21,14,3,42,7,42,21,14,21,6,7,42,21,14,21,42,1,0,0,0,0,0,0,0,0,0,0,0,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,1,0,0,0,0,0,0,0,0,0,0,0,0,40,20,40,10,8,20,40,5,40,4,40,10,40,20,8,5,40,20,40,2,40,20,40,5,8,20,40,10,40,4,40,5,40,20,8,10,40,20,40,1,0,0,0,0,0,0,0,0,0,0,0,0,0,39,39,13,39,39,13,39,39,13,39,39,13,3,39,13,39,39,13,39,39,13,39,39,13,39,3,13,39,39,13,39,39,13,39,39,13,39,39,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,38,19,38,19,38,19,38,19,38,19,38,19,38,19,38,19,38,19,2,19,38,19,38,19,38,19,38,19,38,19,38,19,38,19,38,19,38,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,36,18,12,9,36,6,36,9,4,18,36,3,36,18,12,9,36,2,36,9,12,18,36,3,36,18,4,9,36,6,36,9,12,18,36,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,35,35,35,35,7,35,5,35,35,7,35,35,35,5,7,35,35,35,35,7,5,35,35,35,7,35,35,5,35,7,35,35,35,35,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,34,17,34,17,34,17,34,17,34,17,34,17,34,17,34,17,2,17,34,17,34,17,34,17,34,17,34,17,34,17,34,17,34,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,33,33,11,33,33,11,33,33,11,33,3,11,33,33,11,33,33,11,33,33,11,3,33,11,33,33,11,33,33,11,33,33,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,16,32,8,32,16,32,4,32,16,32,8,32,16,32,2,32,16,32,8,32,16,32,4,32,16,32,8,32,16,32,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,30,15,10,15,6,5,30,15,10,3,30,5,30,15,2,15,30,5,30,3,10,15,30,5,6,15,10,15,30,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,14,28,7,28,14,4,7,28,14,28,7,28,2,28,7,28,14,28,7,4,14,28,7,28,14,28,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,27,9,27,27,9,27,27,3,27,27,9,27,27,9,27,27,3,27,27,9,27,27,9,27,27,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26,13,26,13,26,13,26,13,26,13,26,13,2,13,26,13,26,13,26,13,26,13,26,13,26,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,25,25,25,5,25,25,25,25,5,25,25,25,25,5,25,25,25,25,5,25,25,25,25,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,12,8,6,24,4,24,3,8,12,24,2,24,12,8,3,24,4,24,6,8,12,24,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,22,11,22,11,22,11,22,11,22,11,2,11,22,11,22,11,22,11,22,11,22,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,21,7,21,21,7,3,21,7,21,21,7,21,3,7,21,21,7,21,21,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20,10,20,5,4,10,20,5,20,2,20,5,20,10,4,5,20,10,20,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,9,6,9,18,3,18,9,2,9,18,3,18,9,6,9,18,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,1,0,0,0,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7,7,7,7,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,3,2,3,6,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,2,4,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
int main(){
int i,n,T,Cas=1,l,r;scanf("%d",&T);
while(T--)
{
for(i=52;i>=1;i--)scanf("%d",&s1[i]);
scanf("%d%d%d",&n,&l,&r);
n%=mod[52-r][52-l]; while(n--) outstack(53-r,53-l);
printf("Case #%d: ",Cas++);
for(i=52;i>1;i--)printf("%d ",s1[i]);
printf("%d\n",s1[i]);
}
return 0;
}
#include<stdio.h>
#define N 53 int s1[N],s2[N],st2;
void outstack(int l,int r){
st2=1;
int i;
for(i=l;i<=r;i++)
s2[st2++]=s1[i];
for(i=l;i+r-l+1<=52;i++)
s1[i]=s1[i+r-l+1];
st2=1;
for(;i<=52;i++)
s1[i]=s2[st2++];
}
bool Is(){
for(int i=1;i<=52;i++)if(i!=s1[i])return false;
return true;
}
int main(){
FILE *fp;
fp=fopen("HDU 4350","w");
for(int i=1;i<=52;i++)s1[i]=i;
for(int i=1;i<=52;i++)
for(int j=1;j<=52;j++)
if(i>j)fprintf(fp,"0,");
else
for(int k=1;;k++)
{
outstack(i,j);
if(Is())
{
fprintf(fp,"%d,",k);
break;
}
}
fclose(fp);
}

HDU 4350 Card的更多相关文章

  1. HDU 4336 Card Collector 期望dp+状压

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...

  2. [HDU 4336] Card Collector (状态压缩概率dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...

  3. HDU 4336 Card Collector 数学期望(容斥原理)

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意简单,直接用容斥原理即可 AC代码: #include <iostream> ...

  4. hdu 5159 Card (期望)

    Problem Description There are x cards on the desk, they are numbered from 1 to x. The score of the c ...

  5. hdu 4336 Card Collector(期望 dp 状态压缩)

    Problem Description In your childhood, people in the famous novel Water Margin, you will win an amaz ...

  6. hdu 1528 Card Game Cheater ( 二分图匹配 )

    题目:点击打开链接 题意:两个人纸牌游戏,牌大的人得分.牌大:2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < ...

  7. HDU 4336 Card Collector(动态规划-概率DP)

    Card Collector Problem Description In your childhood, do you crazy for collecting the beautiful card ...

  8. hdu 4336 Card Collector——最值反演

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336 点集中最早出现的元素的期望是 min ,最晚出现的元素的期望是 max :全部出现的期望就是最晚出现 ...

  9. HDU 5159 Card

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5159 题解: 考虑没一个数的贡献,一个数一次都不出现的次数是(x-1)^b,而总的排列次数是x^b, ...

随机推荐

  1. c++的引用(二)

    /*按地址传递*/ #include <iostream> using namespace std; void swap(int *a, int *b) { int c; c = *a; ...

  2. [Swust OJ 179]--火柴棍(找规律)

    题目链接:http://acm.swust.edu.cn/problem/0179/ Time limit(ms): 1000 Memory limit(kb): 65535   Descriptio ...

  3. [Swust OJ 585]--倒金字塔(LIS最长不下降子序列)

    题目链接:http://acm.swust.edu.cn/problem/585/ Time limit(ms): 3000 Memory limit(kb): 65535   SWUST国的一支科学 ...

  4. BZOJ 1798: [Ahoi2009]Seq 维护序列seq( 线段树 )

    线段树.. 打个 mul , add 的标记就好了.. 这个速度好像还挺快的...( 相比我其他代码 = = ) 好像是#35.. ---------------------------------- ...

  5. USACO Healthy Holsteins DFS

    使用排列组合,遍历所有可能的情况C(1)+C(2)+C(3)……C(n)= 2^G种组合 数据规模不大,暴力过去最多也就是2^15 = 23768种情况 所以就暴力咯,不过还是Debug了一会 Sou ...

  6. 模拟Struts2的AOP实现

    在Struts2中有拦截器的概念,通过它的拦截器可以拦截Action.Struts2的拦截器是通过AOP来实现的,在Spring也有类似的概念.下面的我们先来比较一下Struts2和Spring中AO ...

  7. Android Matrix(坐标矩阵)

    Android Matrix 2016-02-26 14:38:10 介绍 中文名:坐标矩阵 高等数学里有介绍,在图像处理方面,主要是用于平面的缩放.平移.旋转等操作. 在Android里面,Matr ...

  8. 【四】注入框架RoboGuice使用:(Your First System Service Injection)

    上一篇我们简单的介绍了一下RoboGuice的使用([三]注入框架RoboGuice使用:(Your First Resource Injection)),今天我们来看下系统服务的使用注解的方法: 为 ...

  9. Android中的Audio播放:控制Audio输出通道切换

    Audio 输出通道有很多,Speaker.headset.bluetooth A2DP等.通话或播放音乐等使用Audio输出过程中,可能发生Audio输出通道的切换.比如,插入有线耳机播放音乐时,声 ...

  10. linux中如何修改文件夹的用户权限 chown命令

    linux中,可以使用chown命令来修改文件夹的用户权限. 1.  以普通用户 A 登录linux,利用su -切换到root用户 2. 在root用户下,可以看到文件夹内容 3. 但通过文件系统, ...