Turn the pokers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 196    Accepted Submission(s): 51
Problem Description
During summer vacation,Alice stay at home for a long time, with nothing to do. She went out and bought m pokers, tending to play poker. But she hated the traditional gameplay. She wants to change. She puts these pokers face down,
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?
 
Input
The input consists of multiple test cases.

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).
 
Output
Output the required answer modulo 1000000009 for each test case, one per line.
 
Sample Input
3 4
3 2 3
3 3
3 2 3
 
Sample Output
8
3
Hint
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)
 
Source
 

题意:
输入操作次数n和扑克牌数m,一開始扑克牌全都背面朝上。如今输入n个数xi,表示每次选择xi张牌翻转。问最后的牌的情况有多少种可能。

思路:
背面为0。正面为1。如果最后能出现x个1,由于每一个牌都是一样的,所以最后x个1的情况有C(m,x)个。
如今问题转化为求最后可能出现几个1。
最后的结果奇偶性同样,由于将1个翻转0变为1个翻转1,1的个数会添加2,反之降低2。
最后的结果肯定是一个连续的奇数或者偶数区间,不可能有间断点,原理同上。
如今的任务就是如何找最大最小值了,假设这次能出现[le,ri]的区间,如今要翻转x次,假设x<=le,那么下次的最小值mi就是le-x了,假设x>le&&x<ri的话,假设le、x同奇偶,mi=0,否则为1,假设x>ri的话,那么mi=x-ri。最大值同理。递推可得到最后的区间。

如今就是要计算C(m,x)了。能够由C(m,0)递推得到,可是涉及到除法,须要用逆元。

代码:
#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 (思维)的更多相关文章

  1. HDU 4869 Turn the pokers(思维+逆元)

    考试的时候没有做出来... 想到了答案一定是一段连续的区间,一直在纠结BFS判断最后的可行1数. 原来直接模拟一遍就可以算出来最后的端点... 剩下的就是组合数取模了,用逆元就行了... # incl ...

  2. HDU 4869 Turn the pokers(推理)

    HDU 4869 Turn the pokers 题目链接 题意:给定n个翻转扑克方式,每次方式相应能够选择当中xi张进行翻转.一共同拥有m张牌.问最后翻转之后的情况数 思路:对于每一些翻转,假设能确 ...

  3. HDU 4869 Turn the pokers(思维+组合公式+高速幂)

    pid=4869" target="_blank">Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i] ...

  4. hdu 4869 Turn the pokers (2014多校联合第一场 I)

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. 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 ...

  6. HDU 4869 Turn the pokers (2014多校联合训练第一场1009) 解题报告(维护区间 + 组合数)

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 4869 Turn the pokers(组合数+费马小定理)

    Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...

  8. HDU 4869 Turn the pokers (2014 多校联合第一场 I)

    HDOJ--4869--Turn the pokers[组合数学+快速幂] 题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次 ...

  9. 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)

    题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...

随机推荐

  1. git 在linux下服务端搭建

    本文以centos为例,其他linux请自行参照对应方式. 1. 服务端安装git yum install git 2. 服务端添加无shell登录权限的用户,将username替换为要添加的用户 u ...

  2. details和summary可以对内容进行折叠

    使用<details>和<summary>元素 它可以在body的任意地方使用下面有一个小例子 <!DOCTYPE html> <html lang=&quo ...

  3. mac下安装HTMLTestRunner

    HTMLTestRunner是Python标准库unittest模块的一个扩展.它生成易于使用的HTML测试报告. 1.下载HTMLTestRunner.py模块地址 http://tungwaiyi ...

  4. java 整型数组基本排序,冒泡,快速选择,插入,归并

    在学java泛型,于是把排序拿来练练手了 import java.util.Arrays; public class GenericArraySort { public static void mai ...

  5. sql2012笔记

    收缩数据库日志文件1.数据库右键-->Options-->Revovery model =Full 改成 Simple2.数据库右键-->Tasks-->Shrink--> ...

  6. VUE环境配置——运行Demo

    如果有Vue的Demo   不知道怎么运行的同学可以看这里 这里只讲Win下面环境配置 一.NodeJs安装 1.下载Windows 安装包(.msi),并安装https://nodejs.org/d ...

  7. Weblogic之简介

    一.简介(来自百度百科)   WebLogic是美国Oracle公司出品的一个application server,确切的说是一个基于JAVAEE架构的中间件,WebLogic是用于开发.集成.部署和 ...

  8. Chapter 8: Exceptional Control Flow

    概述: 我们可以用一种“流”的概念来理解处理器的工作流程,PC(Program Counter)依次为a0,a1,a2,...,an-1,这个序列可以称作control flow.当然我们并不总是按顺 ...

  9. lumen 中间件详解

    我来给大家,讲解一下lumen中的中间件,高手勿喷. 首先,我们看下lumen中文档中的写法,我这里看的是5.3中文文档.https://lumen.laravel-china.org/docs/5. ...

  10. cmd markdown 使用教程

    cmd markdown 使用教程 tags: 自制教程 李卓伦 目录: [TOC] 一.简介与安装 我们理解您需要更便捷更高效的工具记录思想,整理笔记.知识,并将其中承载的价值传播给他人,Cmd M ...