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. day1 python 基础

    # 一行注释"""多行注释"""print("hello world\n" * 3)name = "sure& ...

  2. css的存在形式

    1.css的样式,可以写在head头中: 1).通过ID(#CC{}) 2).通过class (.cc{}) 2.可以将样式,单独写入css的某一个页中 1)通过在head头中,引改该css样式,通过 ...

  3. hdfs深入:10、hdfs的javaAPI操作

    /** * 递归遍历hdfs中所有的文件路径 */ @Test public void getAllHdfsFilePath() throws URISyntaxException, IOExcept ...

  4. SpringBoot中部署Swagger2和Swagger-UI

    1 Gradle配置在dependencies中添加以下依赖: implementation("io.springfox:springfox-swagger2:2.7.0") im ...

  5. sysbench--mysql测试

    1.下载sysbench-0.4.12.14.tar.gz 2.解压.tar -zxf sysbench-0.4.12.14.tar.gz 3.编译: 填写mysql路劲. ./configure - ...

  6. 【转】WinAPI: CreateFontIndirect - 根据字体结构建立逻辑字体

    //声明: CreateFontIndirect( const p1: TLogFont {字体结构} ): HFONT; {返回新字体指针} //TLogFont 是 tagLOGFONTA 结构的 ...

  7. JavaScript中数据类型的转换规则

    JavaScript中数据类型的转换规则 制作人:全心全意 JavaScript是一种无类型语言,也就是说,在声明变量时无须指定数据类型,这使得JavaScript更具有灵活性和简单性. 在代码执行过 ...

  8. atom 安装插件列表

    插件列表 atom-beautify docblockr autocomplete-python goto-definition platformio-ide-terminal symbols-tre ...

  9. LeetCode(60) Permutation Sequence

    题目 The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of th ...

  10. Java字符拼成图片(image-ASCII)

    目录 背景 代码思路 难点讲解 如何得到rgb 如何让不同颜色匹配不同字符 为什么我的图片只能打一半 OutOfMemoryError错误 为什么用汉字来打印图案会扭曲 装逼时刻 @(Java字符图片 ...