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最少 ...
随机推荐
- 安卓 Android 简单数据库(增删改查)
<Button android:id="@+id/delete_btn" android:layout_width="wrap_content" andr ...
- listener.log文件过大导致oracle假死
/home/u01/oracle/product/11gr2/db_1/log/diag/tnslsnr/VM_179_95_centos/listener/trace/listener.log li ...
- ehcache的学习笔记(一)
学习ehcache文档: 介绍:Ehcache是一个开源的项目,用来提高性能的基于标准化的缓存,无需使用数据库,简化了可扩展性.他是最广泛使用的基于java的缓存,因为他是强壮的,被证实的,功能全面的 ...
- winform 实现两个datagridview之间的数据联动
再做数据库开发的时候,经常会遇到表带上明细表,比如,一个学校有好多系,每个系又有好多专业.... 在winform中,都会使用datagridview来显示数据,现在就来说说如何实现之间的联动.比如现 ...
- LeetCode 122. Best Time to Buy and Sell Stock II (stock problem)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- fielddata breaker与cache size
breaker的估算,是根据语句以及上层的结果数,加上固定的值,不准确. cache.size是cache到结果的size,准确. 所以,配置breaker不能拦截占用内存的聚合查询,而配置cache ...
- xtu summer individual-4 A - Beautiful IP Addresses
Beautiful IP Addresses Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on Code ...
- thinkphp整合系列之微信公众号支付
<?phperror_reporting(E_ALL);ini_set('display_errors', '1');// 定义时区ini_set('date.timezone','Asia/S ...
- java springMVC 极致验证 非demo版
最近公司项目需要,做了个极致验证,自己在此做下记录. 先上效果图: 它的官网:http://www.geetest.com/ 里面有 身份验证.行为验证, 我这使用的为行为验证. 技术文档:ht ...
- Sumdiv(poj1845)
题意:求A^B的因子的和. /* 首先将A分解 A=p1^a1*p2^a2*...*pn*an A^B=p1^a1B*p2^a2B*...*pn*anB 因子之和sum=(1+p1+p1^2+...+ ...