![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
容斥原理
mmk27
这个作者很懒,什么都没留下…
展开
-
HDU - 1796 How many integers can you find 容斥原理
Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N=12, and M-integer s...原创 2018-10-29 14:51:39 · 128 阅读 · 0 评论 -
HDU - 4790 Just Random 容斥
题目链接:https://cn.vjudge.net/problem/HDU-4790题意:x属于[a, b],y属于[c, d],任取x,y,求满足(x + y) mod p = m的概率题解:大致就应该想到容斥来求,像这样 get(b, d) - get(a - 1, d) - get(c- 1, b) + get(a - 1, c - 1),比如求[0, x]和[0, y],先对两个...原创 2019-07-02 11:53:34 · 133 阅读 · 0 评论 -
Contest1789 - 2019年第二阶段我要变强个人训练赛第十二场 问题 H: 计数JS 容斥 JAVA大数
题目描述给定一个长度为n的序列a1..an,求m以内的不能被a1..an中任意一个ai整除的正整数有多少个?输入第一行两个数n,m接下来一行n个数,a1..an输出共一个数,即m以内的不能被a1..an中任意一个ai整除的正整数有多少个。样例输入复制样例数据3 20154 5 6样例输出1075提示对于...原创 2019-07-08 09:36:00 · 234 阅读 · 0 评论 -
HDU - 5213 Lucky 莫队+容斥
题目链接:https://cn.vjudge.net/problem/HDU-5213题意:从两个区间中各拿一个数,和为k的选法题解:容斥一下即为:sum[l, v] - sum[l, u-1] -sum[r+1, v] + sum[r+1, u-1] sum[l, r] 表示从[l,r]中选择两个数和为k的选法,剩下的就莫队分块解决一下就可以了#inclu...原创 2019-05-15 17:32:15 · 156 阅读 · 0 评论 -
Gym - 100548F Color 组合数+容斥
题意:给你N朵花,M种颜料(n,m<=1e9),要求给所有花染色,且相邻的花不能用同样的颜色,求出最后恰好用了k种颜料的方案数(k<=1e5)题解:当我们用至少k中染色的时候 f[k] = k*(k-1)^(n-1) 其中包括了 至少k-1中的,我们需要减去C(k,k-1)*f[k-1] ,但是很明显我们多减了一次至少f[k-2]次的,举个栗子:假设有1 2 3 4 5,我...原创 2018-10-30 14:28:21 · 194 阅读 · 0 评论 -
HDU - 1695 容斥+欧拉函数
Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = k. GCD(x, y) means the greatest common divisor of x and y. Since the number of choices may be very large, you're...原创 2018-10-31 13:02:15 · 118 阅读 · 0 评论 -
HDU - 5468 Puzzled Elena dfs+容斥
Since both Stefan and Damon fell in love with Elena, and it was really difficult for her to choose. Bonnie, her best friend, suggested her to throw a question to them, and she would choose the one who...原创 2018-09-14 17:44:48 · 142 阅读 · 0 评论 -
HDU - 2841 Visible Trees 容斥
There are many trees forming a m * n grid, the grid starts from (1,1). Farmer Sherlock is standing at (0,0) point. He wonders how many trees he can see.If two trees and Sherlock are in one line, Farm...原创 2018-10-29 15:04:59 · 106 阅读 · 1 评论 -
HDU - 2204 Eddy's爱好 容斥
Ignatius 喜欢收集蝴蝶标本和邮票,但是Eddy的爱好很特别,他对数字比较感兴趣,他曾经一度沉迷于素数,而现在他对于一些新的特殊数比较有兴趣。这些特殊数是这样的:这些数都能表示成M^K,M和K是正整数且K>1。正当他再度沉迷的时候,他发现不知道什么时候才能知道这样的数字的数量,因此他又求助于你这位聪明的程序员,请你帮他用程序解决这个问题。为了简化,问题是这样的:给你一个正整数N,...原创 2018-10-29 14:57:27 · 96 阅读 · 0 评论 -
CodeForces - 369E Valera and Queries 树状数组+离线+容斥思想
题目链接:https://vjudge.net/problem/CodeForces-369E题意:n条线段,m次询问,给出cnt个点,问这些点在多少线段上题解:如果每个点对于所在的线段上没有影响的话,那么我们就可以建立权值线段树,直接查询即可,但是存在多个点在一条直线的情况,所以就没法这么搞了,所以我们可以把查询的点转化成间隔的线段,计算出有多少线段在这些线段上,这样我们离线记录下来,就...原创 2019-10-03 20:41:38 · 148 阅读 · 0 评论