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, ...
随机推荐
- 一个IP每天只弹一次广告窗口
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- SB中使用Autolayout设置到父视图的间距为0
发现打上钩的话在plus以下的屏幕上控件的实际x会是-4但是在plus上是0, 所以要设置一致的到视图的左右都未0 必须把Constrain to margins钩去掉!
- E - Phone List(字典序,string类型使用)
Description Given a list of phone numbers, determine if it is consistent in the sense that no number ...
- Cin、Cout 加快效率方法
std::ios::sync_with_stdio(false); 在main 函数中加上这么一句话. 可以打消iostream的输入输出缓存,可以节省许多时间,使效率与scanf与printf相差无 ...
- MVC-03 控制器(4)
七.模型绑定 在ASP.NET MVC中是通过模型绑定(Model Binding)达到解析客户端传来的数据. 1.简单模型绑定 当网页上有个窗体,且窗体内有个名为Username的输入字段,而Act ...
- 打工心态废掉了很多人,包括你吗?(你把现在这家公司的业务都弄清楚、弄懂了吗?君子报仇十年不晚!不离不弃!)good
我只拿这点钱,凭什么去做那么多工作,我傻呀. 我为公司干活,公司付我一份报酬,等价交换而已,我不欠谁的. 我只要对得起这份薪水就行了,多一点我都不干,做了也白做. 工作嘛,又不是为自己干,说得过去就行 ...
- Android Support Library更新到v22.1之AppCompat新特性
构建一个可以跑在不同版本 Android 平台的软件,是非常复杂和耗时的.为了解决这个问题,Android 推出了 Android Support Library (安卓兼容包),让新的UI控件也可以 ...
- 关于ActionContext.getContext()的使用方法心得
这个也是我在另外一位仁兄的博客中看到的,原博客的有点长,我把它精简了一下,算看起来比較方便吧. 为了避免与Servlet API耦合在一起,方便Action类做单元測试,Struts 2对HttpSe ...
- 过渡到SSAS之一:简单模型认识
本文主要是转载的,但有些地方,原作者没有说的够详细,我加以补充发到这里. --------------------------------------------------------------- ...
- Permutations【python】
class Solution: # @param num, a list of integer # @return a list of lists of integers def permute(se ...