zoj 2836 容斥原理】的更多相关文章

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2836 #include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <queue> #include <vector> #define maxn…
Number Puzzle Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a list of integers (A1, A2, ..., An), and a positive integer M, please find the number of positive integers that are not greater than M and dividable by any integer from the given…
求不比M大的可以被集合任一个数整除的数的个数.(容斥原理) #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int set[15]; int ans; int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b); } void dfs(int i,int…
题意:给出n个数,和m(1<=m<=200 000 000),求1~M中能被这n个数其中任意一个数整除的个数: 分析:n范围很小,可以枚举选择被哪些数整除,被奇数个整数整除加m/这个n个数的公共最小公倍数: #include <bits/stdc++.h> using namespace std; ]; int gcd (int a,int b) { ? a:gcd(b,a%b); } int lcm(int a,int b) { return a*b/gcd(a,b); } in…
题面 lcm(x,y)=xy/gcd(x,y) lcm(x1,x2,···,xn)=lcm(lcm(x1,x2,···,xn-1),xn) #include <bits/stdc++.h> using namespace std; long long n,m; ]; long long gcd(long long a,long long b) { if(!b){ return a; } return gcd(b,a%b); } long long lcm(long long a,long lo…
√√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 1.1 例 3」喷水装置 √√#10003 「一本通 1.1 例 4」加工生产调度 √√#10004 「一本通 1.1 例 5」智力大冲浪 √√#10005 「一本通 1.1 练习 1」数列极差 √√#10006 「一本通 1.1 练习 2」数列分段 √√#10007 「一本通 1.1 练习 3」线…
主题链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4535 How Many Sets I Time Limit: 2 Seconds      Memory Limit: 65536 KB Give a set S, |S| = n, then how many ordered set group (S1, S2, ..., Sk) satisfies S1 ∩ S2 ∩ ... ∩ Sk = ∅. (Si is…
这题被出题人给活活坑了,题目居然理解错了..哎,不想多说. 题意:给两组数,A组为幸运基数,B组为不幸运的基数,问在[low,high]区间内有多少个数:至少被A组中一个数整除,并且不被B中任意一个数整除.|A|<=15. 分析:看到A长度这么小,以及求区间内满足条件的个数问题,容易想到容斥原理,因为不被B中任意一个数整除,所以将B数组所有数取一个最小公倍数LCM,那么就变成了幸运数字都不会被这个LCM整除. 然后枚举子集,实现要将A中元素去除相互整除的情况,比如A = [2,4],这时因为被至…
一道纯粹的容斥原理题!!不过有一个trick,就是会出现重复的,害我WA了几次!! 代码: #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<set> #include<vector> #define ll long long #define mod 55566677 usin…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=442 求解 x1 + x2 + x3 + .... + xn = m 其中xi属于[L, R] 不同解的个数. 这题需要用大数,要注意. 原理和以前做的一样.容斥.先算出每个xi大于等于Li的解的个数.关于这个,怎么解,看看: http://www.cnblogs.com/liuweimingcprogram/p/6091396.html 然后容斥吧,枚举有一个数破坏条件,就是…