Turn the pokers

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

Total Submission(s): 108    Accepted Submission(s): 21

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
 

    解题报告:非常奇妙的题目。基本是依照官方解题报告来写的代码。
    简单来说。用 l 和 r 记录最少移动了多少牌,和最多移动了多少牌。最后用组合数求和就是答案。

一张牌翻两次等于没有翻。所以l。r应该是奇偶性同样,且l。r范围内都是解。

    代码例如以下:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
using namespace std; #define ff(i, n) for(int i=0;i<(n);i++)
#define fff(i, n, m) for(int i=(n);i<=(m);i++)
#define dff(i, n, m) for(int i=(n);i>=(m);i--)
typedef long long LL;
typedef unsigned long long ULL;
void work(); int main()
{
#ifdef ACM
freopen("in.txt", "r", stdin);
#endif // ACM work();
} /***************************************************/ const int mod = 1000000009; int powMod(LL a, int b)
{
LL res = 1;
while(b)
{
if(b&1)
res = res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
} int inv[111111]; void work()
{
// 初始化,求出1-100000在模1000000009系下的逆元
fff(i, 1, 100000)
inv[i] = powMod(i, mod-2); int n, m;
while(~scanf("%d%d", &n, &m))
{
int l = 0, r = 0;
int ll, rr; ff(i, n)
{
int x;
scanf("%d", &x); if(r + x <= m)
rr = r + x;
else if(l + x <= m)
rr = ((m + l + x)&1) ? m-1 : m;
else
rr = 2 * m - l - x; if(l - x >= 0)
ll = l - x;
else if(r - x >= 0)
ll = ((l + x)&1);
else
ll = x - r; l = ll, r = rr;
} LL ans = 0; LL c = 1;
fff(i, 0, m)
{
if(i == l)
{
ans += c;
l += 2;
if(l > r) break;
} c = c * (m-i) % mod * inv[i+1] % mod;
} printf("%I64d\n", ans%mod);
}
}

HDU 4869 Turn the pokers (2014多校联合训练第一场1009) 解题报告(维护区间 + 组合数)的更多相关文章

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

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

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

  3. 2015年多校联合训练第一场OO’s Sequence(hdu5288)

    题意:给定一个长度为n的序列,规定f(l,r)是对于l,r范围内的某个数字a[i],都不能找到一个相应的j使得a[i]%a[j]=0.那么l,r内有多少个i,f(l,r)就是几. 问全部f(l,r)的 ...

  4. 2015多校联合训练第一场Tricks Device(hdu5294)

    题意:给一个无向图,给起点s,终点t,求最少拆掉几条边使得s到不了t,最多拆几条边使得s能到t 思路: 先跑一边最短路,记录最短路中最短的边数.总边数-最短边数就是第二个答案 第一个答案就是在最短路里 ...

  5. HDU 4869 Turn the pokers(推理)

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

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

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

  7. hdu 4869 Turn the pokers (思维)

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

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

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

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

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

随机推荐

  1. 迅为电子HMI人机界面|CAN总线触摸屏

    本文转自迅为:http://www.topeet.com 协议特色: 1. 支持所有 CAN 协议,例如常用的 J1939 和 CANopen 协议. 2. 提供高度开放的 CAN 帧的编辑界面,用户 ...

  2. ALTER GROUP - 修改一个用户组

    SYNOPSIS ALTER GROUP groupname ADD USER username [, ... ] ALTER GROUP groupname DROP USER username [ ...

  3. 开放API接口

    [开放API]——知乎.博客园等开放API接口(更新ing)   Cnodejs.org: https://cnodejs.org/api/ 和风天气: http://docs.heweather.c ...

  4. thinkphp5中extend的使用?

    1.创建处理数组的类ArrayList.php <?php /** * ArrayList实现类 * @author liu21st <liu21st@gmail.com> */ c ...

  5. POJ 1637 Sightseeing tour 建图+网络流

    题意: 给定一个混合图,所谓混合图就是图中既有单向边也有双向边,现在求这样的图是否存在欧拉回路. 分析: 存在欧拉回路的有向图,必须满足[入度==出度],现在,有些边已经被定向,所以我们直接记录度数即 ...

  6. SpringAOP的简单实现

    AOP,即面向切面编程,springAOP采用的是动态代理的技术 其主要作用可以做一些与业务逻辑无关,但却必须的操作,例如日志记录,权限管理,检查数据,等等.首先,来做一个小实现来方便理解 首先,建立 ...

  7. Python 函数递归-三元表达式-列表生成式-字典生成式-匿名函数-内置函数

    上节课复习: 1. 无参装饰器 def 装饰器名字(func): def wrapper(*args,**kwargs): res = func(*args,**kwargs) return res ...

  8. [Python3网络爬虫开发实战] 1.7.2-mitmproxy的安装

    mitmproxy是一个支持HTTP和HTTPS的抓包程序,类似Fiddler.Charles的功能,只不过它通过控制台的形式操作. 此外,mitmproxy还有两个关联组件,一个是mitmdump, ...

  9. 标量子查询中有ROWNUM=1怎么改?

    碰到标量子查询中有ROWNUM=1怎么改? select to_date(o.postdate,'yyyymmdd'), (select cur.c_code from cur_tbl cur whe ...

  10. js 技巧 (六)JavaScript[对象.属性]集锦

    JavaScript[对象.属性]集锦 SCRIPT 标记 用于包含javascript代码. 语法 属性 LANGUAGE 定义脚本语言 SRC 定义一个URL用以指定以.JS结尾的文件 windo ...