HDU 4869 Turn the pokers(推理)】的更多相关文章

HDU 4869 Turn the pokers 题目链接 题意:给定n个翻转扑克方式,每次方式相应能够选择当中xi张进行翻转.一共同拥有m张牌.问最后翻转之后的情况数 思路:对于每一些翻转,假设能确定终于正面向上张数的情况,那么全部的情况就是全部情况的C(m, 张数)之和.那么这个张数进行推理会发现,事实上会有一个上下界,每隔2个位置的数字就是能够的方案,由于在翻牌的时候,相应的肯定会有牌被翻转,而假设向上牌少翻一张,向下牌就要多翻一张.奇偶性是不变的,因此仅仅要每次输入张数,维护上下界,最后…
Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1265    Accepted Submission(s): 465 Problem Description During summer vacation,Alice stay at home for a long time, with nothing t…
pid=4869" target="_blank">Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i]代表能够翻的扑克的个数,求最后可能出现的扑克的组合情况. Hint Sample Input: 3 3 3 2 3 For the this example: 0 express face down,1 express face up Initial state 000 The first result:00…
Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1064    Accepted Submission(s): 398 Problem Description During summer vacation,Alice stay at home for a long time, with nothing to…
Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 196    Accepted Submission(s): 51 Problem Description During summer vacation,Alice stay at home for a long time, with nothing to…
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…
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,…
HDOJ--4869--Turn the pokers[组合数学+快速幂] 题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次翻牌后牌的朝向有多少种情况.我们可以把正面朝上理解为1,反面朝上理解为0,那么可以理解为求01串的不同的组合方式有几种. 解题思路:我们可以知道,每张牌假设起始状态都为0,如果翻奇数次,该牌最后的情况是1,如果翻偶数次,该牌的最后情况为0.根据n次翻牌的个数找出1的个数的下限和上限,然后再在这个范围…
题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少时最少的个数,rb代表1最多时的个数.一张牌翻两次和两张牌翻一次 得到的奇偶性相同,所以结果中lb和最多的rb的奇偶性相同.如果找到了lb和rb,那么,介于这两个数之间且与这两个数奇偶性相同的数均可取到,然后在这个区间内求组合数相加(若lb=3,rb=7,则3,5,7这些情况都能取到,也就是说最后的…
考试的时候没有做出来... 想到了答案一定是一段连续的区间,一直在纠结BFS判断最后的可行1数. 原来直接模拟一遍就可以算出来最后的端点... 剩下的就是组合数取模了,用逆元就行了... # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # includ…
题意:输入操作次数n和扑克牌数m,一開始扑克牌全都背面朝上. 如今输入n个数xi,表示选择xi张牌翻转,问最后的牌的情况有多少种可能? 题解: 我们将一開始的牌觉得是m个0.而翻转就是将0变成1或者1变成0. 最后的答案就是ans=∑C(m,k).C(m.k)为组合数,k为全部能取到的1的可能个数.具体的解释,先了解最后1的个数的奇偶性,跟全部翻牌数的和的奇偶同样(每次翻牌,要么0->1.要么1->0,都是在改变1的个数奇偶).之后我们须要找到最少有i个1,以及最大有j个1:i的情况就是有1就…
最后的结果中正面向上的奇偶性是一定的,计算出正面向上的范围low,up 结果即为 C(m.low)+ C(m.low+2) +.... + C(m,up) ,用逆元取模 Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 828    Accepted Submission(s): 302 Problem D…
Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 316    Accepted Submission(s): 101 Problem Description During summer vacation,Alice stay at home for a long time, with nothing to…
Problem Turn the pokers (HDU 4869) 题目大意 有m张牌,全为正面朝上.进行n次操作,每次可以将任意ai张反面,询问n次操作可能的状态数. 解题分析 记正面朝上为1,朝下为0. 若最后有x个1,则对答案的贡献为C(n,x).所以只需要知道最后可能的1的个数. 假设已经有a个1,某次操作可以将b张牌反面,可以发现操作之后可能的1的个数相差2. 记录每次操作后1的个数所在区间为[l ,r],即可能取到的个数为l , l+2 , l+4 , ...... , r . 每…
原题:  Turn the pokers       思路:假设正面为0,反面为1.牌就像这样 000000....... .考虑到假如可以实现最终反面个数为m, 牌共n张, 则这n张排任取m个为反面其余都为正面的状况都能实现.于是转化为考虑最终可能出现1的个数的集合有哪些.       因为可能的个数集合是连续的(在最大最小值之内相差2的都可能), 所以每一次翻转之后的上下限都可以根据上一次所得的上下限推出.       最后算排列组合的适合需要用到组合数递推公式和费马小定理推论\( a^{p…
题目链接:hdu 4869 Task 题目大意:有n台机器,m个任务.每一个机器和任务都有有xi和yi.要求机器的xi.yi均大于等于任务的xi和yi才干运行任务. 每台机器一天仅仅能运行一个任务.要求完毕的任务数尽量多,而且说金额尽量大. 完毕每一个任务的金额为xi∗500+yi∗2 解题思路:贪心,mach[i][j]表示等级为i,时间为j的机器数量,task[i][j]表示等级为i,时间为j的机器数量. 每次优先降低i,由于相应等级降低100,相应的金额代价也不会降低超过500(即时间降低…
托一个学弟的福,学了一下他的最简便三分写法,然后找了一道三分的题验证了下,AC了一题,写法确实方便,还是我太弱了,漫漫AC路!各路大神,以后你们有啥好的简便写法可以在博客下方留个言或私信我,谢谢了! Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3196    Accepted Submission(s…
HDU 4925 Apple Tree 题目链接 题意:给一个m*n矩阵种树,每一个位置能够选择种树或者施肥,假设种上去的位置就不能施肥,假设施肥则能让周围果树产量乘2.问最大收益 思路:推理得到肯定是果树和肥料交叉种好,类似国际象棋棋盘,黑的种,白的施肥.因为格子数不多,直接去枚举每一个位置就可以.假设题目格子数多的话.事实上也能够推出公式一步得到答案 代码: #include <cstdio> #include <cstring> const int d[4][2] = {{0…
HDU 4924 Room and Moor 题目链接 题意:给定一个01组成的a序列.要求一个b序列,b序列每一个数值为[0, 1]之间的数,而且b序列为非递减序列,要求∑(ai−bi)2最小,求这个最小值 思路:推理,非常easy看出,开头一段的0和末尾一段的1等于没有.然后中间每段相似111000这样1在前,0在后的序列.都能够列出一个公式,非常easy推出选择的x为共同的一个值,为1的个数/(1的个数+0的个数)a,那么问题就变成要维护一个递增的x.利用一个栈去做维护,假设遇到一个位置递…
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,…
http://acm.hdu.edu.cn/showproblem.php?pid=3912 这个题我用递归深搜模拟,直接爆栈了.哭啊!为什么! 这个题最主要是能走重复格子,但是方向不一样. 我用的剪枝条件:         1.判断有没有走出迷宫,走出迷宫了直接退出.         2.由于题目要求只要判断有没有把所有格子走完,则可以用一个计数器统计走过格子的数量(重复走的不算).走完了所有格子则直接退出搜索.         3.在这个格子,当前走的方向以前走过,则重复了(判重) 别人的代…
Problem Description Mr. West bought a new car! So he is travelling around the city. One day he comes to a vertical corner. The street he is currently in has a width x, the street he wants to turn to has a width y. The car has a length l and a width d…
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,…
Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2229    Accepted Submission(s): 856 Problem Description Mr. West bought a new car! So he is travelling around the city. One day h…
传送门 Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2081    Accepted Submission(s): 787 Problem Description Mr. West bought a new car! So he is travelling around the city. One da…
一个机智题,可惜比赛的时候没有机智出来 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define ll long long #define mod 1000000009 #define maxn 100009 using namespace std; ll c[maxn]; void gcd(ll a,ll b,ll &d,ll &x,ll &…
题意: 给出n次翻转和m张牌,牌相同且一开始背面向上,输入n个数xi,表示xi张牌翻转,问最后得到的牌的情况的总数. 思路: 首先我们可以假设一开始牌背面状态为0,正面则为1,最后即是求ΣC(m,k),k为所有能取到1的情况.首先我们要确认最后1的奇偶性.因为一次翻转0->1,或者1->0,则最后所有1的情况的奇偶性相同.然后我们要找到最小的1的个数i和最大的1的个数j,i为能翻1则翻1,j为能翻0则翻0,介于中间的情况是取偶数步数,一半翻1,一半翻0,保持1的个数不变.那么k为(i<=…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4869 Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2001    Accepted Submission(s): 707 Problem Description During summer vacation…
                                                               B. The Meeting Place Cannot Be Changed The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost build…
Least Common Multiple http://acm.hdu.edu.cn/showproblem.php?pid=1019 #include<cstdio> int gcd(int a,int b){ return b?gcd(b,a%b):a; } int lcm(int a,int b){ return a/gcd(a,b)*b; } int main(){ int n,m,ans,x; while(~scanf("%d",&n)){ while(…