Turn the pokers
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).
test case, one per line.
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)
假设第i次操作后有x1个1,第i+1次操作x2个数,假设在xi中操作了i个数,在n-xi中操作了j个数,i+j=x2;操作后有Z个1,
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define mod 1000000009
#define LL __int64
#define maxn 100000+5 LL f[maxn]; void set()
{
int i;
f[] = ;
for(i = ; i<maxn; i++)
f[i] = (f[i-]*i)%mod;
} LL quickmod(LL a,LL b)
{
LL ans = ;
while(b)
{
if(b&)
{
ans = (ans*a)%mod;
b--;
}
b/=;
a = ((a%mod)*(a%mod))%mod;
}
return ans;
} int main()
{
int n,m,i,j,k,l,r,x,ll,rr;
set();
while(~scanf("%d%d",&n,&m))
{
l = r = ;
for(i = ; i<n; i++)
{
scanf("%d",&x);
//计算最小的1的个数,尽可能多的让1->0
if(l>=x) ll = l-x;//当最小的1个数大于x,把x个1全部翻转
else if(r>=x) ll = ((l%)==(x%))?:;//当l<x<=r,由于无论怎么翻,其奇偶性必定相等,所以看l的奇偶性与x是否相同,相同那么知道最小必定变为0,否则变为1
else ll = x-r;//当x>r,那么在把1全部变为0的同时,还有x-r个0变为1
//计算最大的1的个数,尽可能多的让0->1
if(r+x<=m) rr = r+x;//当r+x<=m的情况下,全部变为1
else if(l+x<=m) rr = (((l+x)%) == (m%)?m:m-);//在r+x>m但是l+x<=m的情况下,也是判断奇偶,同态那么必定在中间有一种能全部变为1,否则至少有一张必定为0
else rr = *m-(l+x);//在l+x>m的情况下,等于我首先把m个1变为了0,那么我还要翻(l+x-m)张,所以最终得到m-(l+x-m)个1 l = ll,r = rr;
}
LL sum = ;
for(i = l; i<=r; i+=)//使用费马小定理和快速幂的方法求和
sum+=((f[m]%mod)*(quickmod((f[i]*f[m-i])%mod,mod-)%mod))%mod;
printf("%I64d\n",sum%mod);
} return ;
}
Turn the pokers的更多相关文章
- HDU-4869 Turn the pokers
原题: Turn the pokers 思路:假设正面为0,反面为1.牌就像这样 000000....... .考虑到假如可以实现最终反面个数为m, 牌共n张, 则这n张排任取m个为反面 ...
- 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多校联合第一场 I)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4869 Turn the pokers(推理)
HDU 4869 Turn the pokers 题目链接 题意:给定n个翻转扑克方式,每次方式相应能够选择当中xi张进行翻转.一共同拥有m张牌.问最后翻转之后的情况数 思路:对于每一些翻转,假设能确 ...
- [hdu 4869](14年多校I题)Turn the pokers 找规律+拓欧逆元
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4869 Turn the pokers (思维)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDOJ 4869 Turn the pokers
最后的结果中正面向上的奇偶性是一定的,计算出正面向上的范围low,up 结果即为 C(m.low)+ C(m.low+2) +.... + C(m,up) ,用逆元取模 Turn the pokers ...
- 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(思维+组合公式+高速幂)
pid=4869" target="_blank">Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i] ...
随机推荐
- Java学习笔记(3)
“当你定义出一组类的父型时,你可以用子型的任何类来填补任何需要或期待父型的位置” “运用多态时,引用类型可以是实际对象类型的父类”Animal myDog = new Dog(); 三种方法可以防止某 ...
- The h.264 Sequence Parameter Set
转债: http://www.cardinalpeak.com/blog/the-h-264-sequence-parameter-set/ View from the Peak The h.264 ...
- Java处理InterruptedException异常小结
对于InterruptedException,一种常见的处理方式是捕捉它,然后什么也不做(或者记录下它,不过这也好不到哪去).不幸的是,这种方法忽略了这样一个事实:这期间可能发生中断,而中断可能导致应 ...
- C++11 能好怎?
0. 摘要 近期读了一些关于C++11标准的材料. 本篇博客将从新标准的优点.与旧版本的区别和使用方法三个角度,大致介绍我对C++11的认识. C++11标准,原名C++0x, 是03版旧标准的更新. ...
- 深入探究frame和bounds的区别以及setbounds使用
[转自]http://blog.csdn.net/hherima/article/details/39501857 在iOS开发中经常遇到两个词Frame和bounds,本文主要阐述Frame和bou ...
- Spring Auto-Wiring Beans
In Spring framework, you can wire beans automatically with auto-wiring feature. To enable it, just d ...
- bzoj 2190 仪仗队(欧拉函数)
2190: [SDOI2008]仪仗队 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 2245 Solved: 1413[Submit][Statu ...
- 对于一个网站,如何禁止直接从浏览器Web browser中访问js文件
比如有一个网站,https://testsystem.infotest.com 在这个网站的内容文件目录下面,有一个scripts文件夹,该文件夹中有一个js文件,比如lukeTest.js文件 这样 ...
- Hql处理日期格式化问题
1. Date date=Calendar.getInstance().getTime(); Date date1=Calendar.getInstance().getTime(); String h ...
- STM32实验非正式报告之DMA
前言 DMA即直接内存存取.我理解它就是一个“交通部长”抑或是一个“搬运工”,协助CPU存储或读取数据.既然它的主要工作就是“搬运”数据,服务对象自然就是内存(不太严格的说法吧,STM32中Flash ...