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. Java集合(三)--Collection、Collections和Arrays

    Collection: Collection是集合类的顶级接口,提供了对集合对象进行基本操作的通用接口方法.Collection接口的意义是为各种具体的集合提供了最大化 的统一操作方式,其直接继承接口 ...

  2. Maven的pom报错的解决方法

    如果在MyEclipse里面导入项目,导入不了,如下图 接下来可以点击Import Maven Projects里的Action那一行Resolve Later. 点击Do Not Execute(a ...

  3. genymotion 双击打开后 图标只显示在任务栏 无法在电脑上显示

    解决办法 删除 c:/users/user/AppData/local/Genymobile  例如:C:\Users\lenovo\AppData\Local\Genymobile 删除注册表:HK ...

  4. iOS工具】rvm、Ruby环境和CocoaPods安装使用及相关报错问题解决

    〇.前言 <p>在iOS开发中 CocoaPods作为库依赖管理工具就是一把利器. 有了 CocoaPods则无需再通过拖 第三方库及第三方库所依赖的 framework静态库到项目中等麻 ...

  5. 解决java web项目导入后出现的问题 ---cannot be read or is not a valid ZIP file

    导入以前的web项目后会出现以下三个错误: 1. Archive for required library: ‘WebContent/WEB-INF/lib/readme.txt’ in projec ...

  6. 17Spring前置通知

    1).加入jar包:下载地址 spring-beans-4.1.6.RELEASE.jar commons-logging-1.1.3.jar spring-context-4.1.6.RELEASE ...

  7. python3 监控代码变化 自动重启 提高开发效率

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = 'Michael Liao' import os, sys, time, sub ...

  8. vscode 解决符号无法识别的问题

    一开始浏览代码出现了下面这个问题, __attribute__ 标记为红色,符号无法识别,下面还出现了很多提示需要加 ), } 等符号,虽然编译没问题,但是看着红色标记和一堆提示真是要逼死强迫症. 既 ...

  9. Error connecting to database: No such file or directory

    标签:Error connecting to database: No such file or directory 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明 ...

  10. css3 & background & background-image

    css3 & background & background-image https://developer.mozilla.org/en-US/docs/Web/CSS/backgr ...