hdu 4869 Turn the pokers (思维)
Turn the pokers
she decided to flip poker n times, and each time she can flip Xi pokers. She wanted to know how many the results does she get. Can you help her solve this problem?
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 4
3 2 3
3 3
3 2 3
8
3HintFor 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)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define maxn 235
#define MAXN 100005
#define mod 1000000009
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-8
typedef long long ll;
using namespace std; ll n,m,ans,flag,cnt,tot;
ll fac[100005],rev[100005]; ll pow_mod(ll a,ll i,ll n) // 高速幂取模
{
if(i==0)return 1%n;
ll temp=pow_mod(a,i>>1,n);
temp=temp*temp%n;
if(i&1)temp=temp*a%n;
return temp;
}
void init() // 初始化
{
fac[0]=rev[0]=1;
for(ll i=1;i<=100000;i++)
fac[i]=fac[i-1]*i%mod,rev[i]=pow_mod(fac[i],mod-2,mod);
}
ll C(ll n,ll m) // 求组合数取mod的值
{
return (fac[n]*rev[m]%mod)*rev[n-m]%mod;
} int main()
{
ll i,j,t,x,le,ri;
init();
while(~scanf("%I64d%I64d",&n,&m))
{
le=ri=0;
for(i=1;i<=n;i++)
{
scanf("%I64d",&x);
ll u,v;
if(x<=le) u=le-x;
else if(x>le&&x<ri)
{
if((x+le)%2==0) u=0;
else u=1;
}
else u=x-ri; if(x<=m-ri) v=ri+x;
else if(x>m-ri&&x<=m-le)
{
if((x+le+m)%2==0) v=m;
else v=m-1;
}
else v=le+(m-le)-(x-(m-le));
le=u,ri=v;
}
// printf("le:%I64d ri:%I64d\n",le,ri);
ans=0;
for(i=le;i<=ri;i+=2)
{
ans+=C(m,i);
ans%=mod;
}
printf("%I64d\n",ans);
}
return 0;
}
hdu 4869 Turn the pokers (思维)的更多相关文章
- HDU 4869 Turn the pokers(思维+逆元)
考试的时候没有做出来... 想到了答案一定是一段连续的区间,一直在纠结BFS判断最后的可行1数. 原来直接模拟一遍就可以算出来最后的端点... 剩下的就是组合数取模了,用逆元就行了... # incl ...
- HDU 4869 Turn the pokers(推理)
HDU 4869 Turn the pokers 题目链接 题意:给定n个翻转扑克方式,每次方式相应能够选择当中xi张进行翻转.一共同拥有m张牌.问最后翻转之后的情况数 思路:对于每一些翻转,假设能确 ...
- HDU 4869 Turn the pokers(思维+组合公式+高速幂)
pid=4869" target="_blank">Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i] ...
- 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 (2014 Multi-University Training Contest 1)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 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(组合数+费马小定理)
Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...
- HDU 4869 Turn the pokers (2014 多校联合第一场 I)
HDOJ--4869--Turn the pokers[组合数学+快速幂] 题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次 ...
- 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)
题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...
随机推荐
- Java面试题解构
有次一个同事让我一同去面试一个候选人,没仔细看简历,所以在问了设计模式之后就让他谈一谈对内存泄漏和垃圾回收的理解,当时候选人一下子就懵了.后来才知道,他面的是初.中级开发职位,想来估计候选人心里也在骂 ...
- queue的入门
#include "iostream"#include "queue" using namespace std; void main12(){ queue &l ...
- C#截取当前活动窗体的图片
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 通过hibernate封装数据库持久化过程回顾泛型/继承/实现等概念
前言 在开发过程中,我们不难发现,客户的需求以及产品的定位对开发内容的走向有很大的决策作用,而这些往往需要在一开始就尽可能考虑周全和设计完善.为什么说是尽可能,因为我们都知道,需求这种东西,一言难尽. ...
- Bean property属性说明
来自为知笔记(Wiz)
- 同步docker的时间
因为在没设置的docker中,其时间与主机相差8小时. 在docker命令行中输入 # echo "Asia/Shanghai" > /etc/timezone# dpkg ...
- 深度学习之tensorflow (一)
一.TensorFlow简介 1.TensorFlow定义: tensor :张量,N维数组 Flow : 流,基于数据流图的计算 TensorFlow : 张量从图像的一端流动到另一端的计算 ...
- VMware下Linux网络配置局域网和外网访问
要使用Linux系统很重要的一个操作就是使Linux系统能够访问互联网,只有Linux系统能够访问互联网才能够去下载很多自己所需要的资源,如果不能访问互联网那么使用Linux系统往往会卡在这一步,假设 ...
- Did you forget about DBModel.InitializeModel the model [AAAdm] ?
AIO5安装完毕后登陆出现以下报错:Did you forget about DBModel.InitializeModel the model [AAAdm] ? 说明: 执行当前 Web 请求期间 ...
- 《java.util.concurrent 包源码阅读》28 Phaser 第二部分
这一部分来分析Phaser关于线程等待的实现.所谓线程等待Phaser的当前phase结束并转到下一个phase的过程.Phaser提供了三个方法: // 不可中断,没有超时的版本 public in ...