hdu 4869 Turn the pokers (思维)
Turn the pokers
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?
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).
3 4
3 2 3
3 3
3 2 3
8
3HintFor 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)
#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 (思维)的更多相关文章
- HDU 4869 Turn the pokers(思维+逆元)
考试的时候没有做出来... 想到了答案一定是一段连续的区间,一直在纠结BFS判断最后的可行1数. 原来直接模拟一遍就可以算出来最后的端点... 剩下的就是组合数取模了,用逆元就行了... # incl ...
- HDU 4869 Turn the pokers(推理)
HDU 4869 Turn the pokers 题目链接 题意:给定n个翻转扑克方式,每次方式相应能够选择当中xi张进行翻转.一共同拥有m张牌.问最后翻转之后的情况数 思路:对于每一些翻转,假设能确 ...
- HDU 4869 Turn the pokers(思维+组合公式+高速幂)
pid=4869" target="_blank">Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i] ...
- 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 (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多校联合训练第一场1009) 解题报告(维护区间 + 组合数)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4869 Turn the pokers(组合数+费马小定理)
Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...
- HDU 4869 Turn the pokers (2014 多校联合第一场 I)
HDOJ--4869--Turn the pokers[组合数学+快速幂] 题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次 ...
- 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)
题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...
随机推荐
- 关于json-lib中日期类型转换的分析与问题解决
说明:本文中的json-lib版本为 <dependency> <groupId>net.sf.json-lib</groupId> <artifactId& ...
- centos6.5安装rabbitmq3.6.14
The minimum version of Erlang/OTP required to run RabbitMQ server 3.6.0 through 3.6.14 is R16B03. St ...
- let 和const与var的不同
1. let的作用域在代码块中仅限在当前的作用于中 { var str1 = 12; console.log(str1); let str2 = 20; console.log(str2); //20 ...
- 使用wwise音效引擎的好处
用过一段时间的wwise,做以下几个具体功能的时候比较方便: 1.当策划需求一个声音需要随机播放多个随机音源的其中一个时,例如脚步声.普通攻击声,当这类声音一直播放的都是同一个音源的时候,人会产生听觉 ...
- .net中LAMBDA表达式常用写法
这里主要是将数据库中的常用操作用LAMBDA表达式重新表示了下,用法不多,但相对较常用,等有时间了还会扩展,并将查询语句及LINQ到时也一并重新整理下: 1.select语句:books.Select ...
- [转载] Linux五种IO模型
转载:http://blog.csdn.net/jay900323/article/details/18141217 Linux五种IO模型性能分析 目录(?)[-] 概念理解 Lin ...
- CLR之委托的揭秘(二)
杂谈 在开始真正的代码之前,分析一下上周的一些工作内容,发现自己在代码上还是有很多小毛病需要纠正和去更改的,首先之前一直疏于文档的整理,几乎很少去写文档,第二对于接口开发过程中缺少一定的严谨性,很多问 ...
- SICK激光雷达LMS511测量数据说明
帧结构说明 LMS511的官方手册存在几个版本,在<Laser Measurement Systems of the LMS500 Product Family>的英文手册中,对单次(连续 ...
- Pyqt5学习系列
最近在学习Pyqt5做界面,找到了一个非常棒的博主的学习系列 在此记录下来: http://blog.csdn.net/zhulove86/article/category/6381941
- P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows
题目描述 约翰家有N头奶牛,第i头奶牛的编号是Si,每头奶牛的编号都是唯一的.这些奶牛最近 在闹脾气,为表达不满的情绪,她们在挤奶的时候一定要排成混乱的队伍.在一只混乱的队 伍中,相邻奶牛的编号之差均 ...