HDU 4869 Turn the pokers (2014 Multi-University Training Contest 1)
Turn the pokers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1064 Accepted Submission(s): 398
Each test case begins with a line containing two non-negative integers n and m(0<n,m<=100000).
The next line contains n integers Xi(0<=Xi<=m).
3 2 3
3 3
3 2 3
3
For the second example:
0 express face down,1 express face up
Initial state 000
The first result:000->111->001->110
The second result:000->111->100->011
The third result:000->111->010->101
So, there are three kinds of results(110,011,101)
最终的结果一定是连续出现的,只需要求出最终的区间。
因为如果对同一张牌进行两次操作,牌的状态不改变。故牌的翻转次数一定是减少偶数次。如果所有数的和是奇数,那么最终结果也一定是奇数。同理,偶数也是一样的。
所以只要递推求出最后的区间,计算sum(C(xi,m)(i=0,1,2。。。)),m是总牌数,xi是在区间内连续的奇数或偶数,在模10^9+9就是最终的答案。
#include <cstdio>
#include <iostream>
#include <cmath>
#define Mod 1000000009
#define max(x,y) ((x)>(y)?x:y)
#define min(x,y) ((x)<(y)?x:y)
using namespace std;
long long J[];
int n,m,a[],l,r,nl,nr;
void Predo(){
J[]=;
for(int i=;i<=;i++)
J[i]=(J[i-]*i)%Mod;
}
long long Q(long long a,long long p){
int e[],k=;
while(p){
e[k++]=p%;
p=p/;
}
long long tmp=;
for(int i=k-;i>=;i--)
if(e[i]) tmp=((tmp*tmp)%Mod*a)%Mod;
else tmp=(tmp*tmp)%Mod;
return tmp;
}
long long C(int n,int m){
return ((J[n]*Q(J[m],Mod-))%Mod*Q(J[n-m],Mod-))%Mod;
}
int main()
{
Predo();
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
int l=r=a[];
for(int i=;i<n;i++){
nl=min(abs(l-a[i]),abs(r-a[i]));
if(l<=a[i]&&a[i]<=r){
if((a[i]-l)%==) nl=;
else nl=;
}
nr=max(l+a[i]<=m?l+a[i]:*m-l-a[i] , r+a[i]<=m?r+a[i]:*m-r-a[i]);
if(m-r<=a[i]&&a[i]<=m-l){
if((a[i]-(m-r))%==) nr=m;
else nr=m-;
}
l=nl;
r=nr;
}
long long ans=;
for(int i=l;i<=r;i=i+)
ans=(ans+C(m,i))%Mod;
printf("%lld\n",ans);
}
return ;
}
HDU 4869 Turn the pokers (2014 Multi-University Training Contest 1)的更多相关文章
- HDU 4869 Turn the pokers (2014多校联合训练第一场1009) 解题报告(维护区间 + 组合数)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4869 Turn the pokers (2014 多校联合第一场 I)
HDOJ--4869--Turn the pokers[组合数学+快速幂] 题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次 ...
- HDU 4869 Turn the pokers(推理)
HDU 4869 Turn the pokers 题目链接 题意:给定n个翻转扑克方式,每次方式相应能够选择当中xi张进行翻转.一共同拥有m张牌.问最后翻转之后的情况数 思路:对于每一些翻转,假设能确 ...
- hdu 4869 Turn the pokers (2014多校联合第一场 I)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4869 Turn the pokers (思维)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4869 Turn the pokers(思维+组合公式+高速幂)
pid=4869" target="_blank">Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i] ...
- 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)
题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...
- hdu 4869 Turn the pokers(组合数+费马小定理)
Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...
- HDU 4869 Turn the pokers(思维+逆元)
考试的时候没有做出来... 想到了答案一定是一段连续的区间,一直在纠结BFS判断最后的可行1数. 原来直接模拟一遍就可以算出来最后的端点... 剩下的就是组合数取模了,用逆元就行了... # incl ...
随机推荐
- Version of SQLite used in Android?
sing the emulators (adb shell sqlite3 --version): SQLite 3.7.11: 19-4.4-KitKat 18-4.3-Jelly Bean 17- ...
- Java 基础学习1 -- 基础语法
1.变量
- 屏蔽ios7中某个页面的默认手势滑回返回
- (void)viewWillDisappear:(BOOL)animated {[super viewWillDisappear:YES];self.navigationController.in ...
- EntityFramework Add方法与Attach区别
一 先发问. 问题:在使用EF过程中,能否有一个方法可以直接执行传入的SQL语句.纠结的只找到了调用存储过程的方法,难道要SqlHelper.cs? 二 友情提示 本文内容参考自MSDN. 三 ...
- Wireshark技巧-过滤规则和显示规则
Wireshark是一个强大的网络协议分析软件,最重要的它是免费软件. 过滤规则 只抓取符合条件的包,在Wireshark通过winpacp抓包时可以过滤掉不符合条件的包,提高我们的分析效率. 如果要 ...
- 'mysql' 不是内部或外部命令,也不是可运行的程序或批处理文件的解决办法
前言: 本文的解决方法来自http://www.cnblogs.com/xionghui/archive/2012/04/11/2442404.html --感谢! 问题描述:新电脑装mysql后在c ...
- 基于AgileEAS.NET企业应用开发平台的分布式解决方案
开篇 分布式应用 AgileEAS.NET基于Microsoft .Net构件技术而构建,Microsoft .Net最吸引人的莫过于分布式应用技术,基已经提供了XML WebService. .Ne ...
- C编程实现2的1000次方(使程序中的n=1000即可)
#include<stdio.h> #include<malloc.h> void double_(int n) { ,j,s,jw=; p=(int *)malloc(siz ...
- hdu 1333 Smith Numbers
刚开始没看清题意,要找的数一定要是素数 ;}
- C# 虚方法的重载 new 与 virtual
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...