HDU 4350 Card
打表找规律,比赛应付了一下,其实还可以把内存再优化一半掉,下面的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,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0,0,0,7,7,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的更多相关文章
- HDU 4336 Card Collector 期望dp+状压
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...
- [HDU 4336] Card Collector (状态压缩概率dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...
- HDU 4336 Card Collector 数学期望(容斥原理)
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意简单,直接用容斥原理即可 AC代码: #include <iostream> ...
- hdu 5159 Card (期望)
Problem Description There are x cards on the desk, they are numbered from 1 to x. The score of the c ...
- hdu 4336 Card Collector(期望 dp 状态压缩)
Problem Description In your childhood, people in the famous novel Water Margin, you will win an amaz ...
- hdu 1528 Card Game Cheater ( 二分图匹配 )
题目:点击打开链接 题意:两个人纸牌游戏,牌大的人得分.牌大:2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < ...
- HDU 4336 Card Collector(动态规划-概率DP)
Card Collector Problem Description In your childhood, do you crazy for collecting the beautiful card ...
- hdu 4336 Card Collector——最值反演
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336 点集中最早出现的元素的期望是 min ,最晚出现的元素的期望是 max :全部出现的期望就是最晚出现 ...
- HDU 5159 Card
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5159 题解: 考虑没一个数的贡献,一个数一次都不出现的次数是(x-1)^b,而总的排列次数是x^b, ...
随机推荐
- Android百度地图定位
在谈到百度地图.如今,每个人都知道这个时候应该可以了吧.而更多的字不拉.直接朝话题. 访问百度地图api您必须应用key,应用在这里key不用说,有官方的文件说明如何应用上述key. 在这里,百度地图 ...
- FFT算法
FFT算法的完整DSP实现 傅里叶变换或者FFT的理论参考: [1] http://www.dspguide.com/ch12/2.htm The Scientist and Engineer's G ...
- linux(Centos 6.3)学习笔记
一.系统分区 1,磁盘分区 使用分区编辑器(partition editor)在磁盘上划分几个逻辑部分.碟片一旦划分成 数个分区,不同类的目录与文件可以存储进不同 ...
- QML在XP等显卡明显不好的情况下 可以参考
http://doc.qt.io/qt-5/windows-requirements.html
- Qt 5.x 全局热键 for windows
Qt 升级到5.x版本后,QAbstractEventDispatcher中函数发生变动,导致libqxt库中的qxtGlobalShortcut挂掉.参考qxtGlobalShortcut写了一个全 ...
- 全球在一个 level 上思考的价值观和想法是一样的(转)
近日,福布斯中文版总编辑周建工对话马云,谈到腾讯频繁的大笔收购,马云点评称腾讯收购的所有的案子,老百性都看得懂,这就错了.战略就像买股票一样,如果老太太都开始买股票了,一定有问题. 以下是对话内容,转 ...
- Android蓝牙A2dp profile的使用
A2dp profile是android支持的一种蓝牙情景模式,一般用于蓝牙立体声耳机,即蓝牙音频的输出 在android的app层中,A2dp的使用并不是很开放,api只提供了非常少的操作接口,连基 ...
- 网页制作之html基础学习1-简介
学习网页制作主要分为三大块 1.HTML 超文本标记语言( 全称:Hyper Text Markup Language) 专门编辑静态网页 2.CSS 网页美化:是HTML控制的样式 ...
- C++ 中mallon动态分配内存大小用法
#include<iostream> using namespace std; int main(){ char *s; int n; cin>>n; s= (char *) ...
- Python 文本解析器
Python 文本解析器 一.课程介绍 本课程讲解一个使用 Python 来解析纯文本生成一个 HTML 页面的小程序. 二.相关技术 Python:一种面向对象.解释型计算机程序设计语言,用它可以做 ...