HDU 4869 Turn the pokers (2014多校联合训练第一场1009) 解题报告(维护区间 + 组合数)
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
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)
一张牌翻两次等于没有翻。所以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) 解题报告(维护区间 + 组合数)的更多相关文章
- HDU 4869 Turn the pokers (2014 多校联合第一场 I)
HDOJ--4869--Turn the pokers[组合数学+快速幂] 题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次 ...
- 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 ...
- 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)的 ...
- 2015多校联合训练第一场Tricks Device(hdu5294)
题意:给一个无向图,给起点s,终点t,求最少拆掉几条边使得s到不了t,最多拆几条边使得s能到t 思路: 先跑一边最短路,记录最短路中最短的边数.总边数-最短边数就是第二个答案 第一个答案就是在最短路里 ...
- HDU 4869 Turn the pokers(推理)
HDU 4869 Turn the pokers 题目链接 题意:给定n个翻转扑克方式,每次方式相应能够选择当中xi张进行翻转.一共同拥有m张牌.问最后翻转之后的情况数 思路:对于每一些翻转,假设能确 ...
- 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 (思维)
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] ...
- 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)
题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...
随机推荐
- JavaSE-14 异常处理
学习要点 使用try-catch-finally处理异常 使用throw.throws抛出异常 异常及其分类 log4j记录日志 异常 1 异常的定义 异常是指在程序的运行过程中所发生的不正常的事件 ...
- 第2节 mapreduce深入学习:13、mapreduce的整个运行过程(多看几遍)
两个问题: 1.mapTaks的个数怎么确认:与block块相关2.reducetask的个数怎么确认:没法确认,需要反复的设置尝试,找到最优值. 手动进行设置 job.setNumReduceTa ...
- Elasticsearch分布式机制和document分析
1. Elasticsearch对复杂分布式机制的透明隐藏特性 1.1)分片机制 1.2)集群发现机制 1.3)shard负载均衡 1.4)shard副本,请求路由,集群扩容,shard重分配 2. ...
- CSU 2018年12月月赛 D 2216 : Words Transformation
Description There are n words, you have to turn them into plural form. If a singular noun ends with ...
- <Redis> 入门一 概念安装
Redis 概念 redis是一款高性能的NOSQL系列的非关系型数据库 什么是NOSQL NoSQL(NoSQL = Not Only SQL),意即“不仅 ...
- Format 格式化函数
转自:老百姓 Format是一个很常用,却又似乎很烦的方法,本人试图对这个方法的帮助进行一些翻译,让它有一个完整的概貌,以供大家查询之用: 首先看它的声明:function Format(const ...
- java成员变量
成员变量是在类范围内定义的变量 局部变量是在一个方法内定义的变量 https://www.cnblogs.com/zhengchenhui/p/5762966.html
- CF-697B Barnicle与691C Exponential notation
无聊写两个题解吧,上午做比赛拉的,感触很多! B. Barnicle time limit per test 1 second memory limit per test 256 megabytes ...
- [HDU2136] Largest prime factor(素数筛)
传送门 题意 给出若干个数n(n<=1000000),求每个n的最大质因子的排名. 质数的排名:如果素数p是第k小的素数,那么p的排名就是k. 思路 乍一看不知道怎么搞. 其实可以想想我们怎么筛 ...
- 【最大流】Escape
https://www.bnuoj.com/v3/contest_show.php?cid=9149#problem/F [题意] 给定n个人和m个星球,每个人可以匹配某些星球,每个星球有一定的容量限 ...