hdu-2841 Visible Trees---容斥定理】的更多相关文章

Visible Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1951    Accepted Submission(s): 792 Problem Description There are many trees forming a m * n grid, the grid starts from (1,1). Farm…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7529    Accepted Submission(s): 2773 Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y…
Problem Description Given a number N, you are asked to count the number of integers between A and B inclusive which are relatively prime to N.Two integers are said to be co-prime or relatively prime if they have no common positive divisors other than…
C - Visible Trees HDU - 2841 思路 :被挡住的那些点(x , y)肯定是 x 与 y不互质.能够由其他坐标的倍数表示,所以就转化成了求那些点 x,y互质 也就是在 1 - m    1 - n 中找互质的对数,容斥 求一下即可 #include<bits/stdc++.h> using namespace std; #define ll long long #define maxn 123456 bool vis[maxn+10]; ll t,n,m,prime[m…
题意:有一块(1,1)到(m,n)的地,从(0,0)看能看到几块(如果两块地到看的地方三点一线,后面的地都看不到). 思路:一开始是想不到容斥...后来发现被遮住的地都有一个特点,若(a,b)有gcd(a,b)!= 1,那么就会被遮住.因为斜率k一样,后面的点会被遮住,如果有gcd,那么除一下就会变成gcd = 1的那个点的斜率了.所以问题转化为求gcd不为1有几个点,固定一个点,然后容斥. #include<set> #include<map> #include<queue…
H - Visible Trees Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2841 Description There are many trees forming a m * n grid, the grid starts from (1,1). Farmer Sherlock is standing at (0,0) poi…
标题效果:给你个m*n方格,广场格从(1,1)开始. 在树中的每个点,然后让你(0,0)点往下看,问:你能看到几棵树. 解题思路:假设你的视线被后面的树和挡住的话以后在这条线上的树你是都看不见的啊.挡住的话就是这个小的方格内对角线的连线过顶点,如图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHUxMjExMDUwMTEyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/g…
Visible Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description 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 ma…
原文链接 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, Farmer Sherlock can only see the tree nearest to…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2841 题意:给n*m的矩阵(从(1,1)开始编号)格子,每个格子有一棵树,人站在(0,0)的位置,求可以看到多少棵树.同一直线上的树只能看到最靠近人的那颗. 思路:可以将题目转化为求gcd(x, y) = 1,(1 <= x <= n, 1 <= y <= m)的对数.直接套用莫比乌斯反演即可. code: #include <cstdio> #include <cs…
/** 大意: 求[1,m], [1,n] 之间有多少个数互素...做了 1695 ,,这题就so easy 了 **/ #include <iostream> #include <cmath> #include <algorithm> using namespace std; ; long long phi[maxn]; long long priD[maxn]; int len ; void euler(long long n){ long long m = (in…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4141    Accepted Submission(s): 1441 Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y)…
How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3315    Accepted Submission(s): 937 Problem Description   Now you get a number N, and a M-integers set, you shoul…
题意:给定区间和n,求区间中与n互素的数的个数, . 思路:利用容斥定理求得先求得区间与n互素的数的个数,设表示区间中与n互素的数的个数, 那么区间中与n互素的数的个数等于.详细分析见求指定区间内与n互素的数的个数 容斥原理 AC代码 #include <cstdio> #include <cmath> #include <cctype> #include <bitset> #include <algorithm> #include <cs…
Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 935    Accepted Submission(s): 339 Problem Description Given a number N, you are asked to count the number of integers between A and B in…
[HDU4135]Co-prime 题意 给出三个整数N,A,B.问在区间[A,B]内,与N互质的数的个数.其中N<=10^9,A,B<=10^15. 分析 容斥定理的模板题.可以通过容斥定理求出[1,n]与x互质的数的个数.方法是先将x进行质因子分解,然后对于每个质因子pi,[1,n]内可以被pi整除的数目为n/pi.可以通过容斥定理解决逆命题,既[1,n]与x不互质的数目.n/p1+n/p2+n/p3-n/p1p2-n/p1p3-n/p2p3+n/p1p2p3.既奇数是加,偶数是减.具体的…
题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=1796 题目大意: 给你一个整数N.和M个整数的集合{A1.A2.-.Am}.集合内元素为非负数(包括零),求小于N的 正整数(1~N-1)中,能被M个整数的集合中随意一个元素整除的正整数个数. 比如N = 12.M = {2,3},在1~N-1中,能被2整除的数为{2,4,6.8.10},能被3整除的数为 {3.6,9}.则所求集合为{2,3,4.6,8,9,10},共7个,则答案为7. 思路:…
http://acm.hdu.edu.cn/showproblem.php?pid=6053 题意:给定一个数组,我们定义一个新的数组b满足bi<ai 求满足gcd(b1,b2....bn)>=2的数组b的个数 题解:利用容斥定理.我们先定义一个集合f(x)表示gcd(b1,b2...bn)为x倍数的个数(x为质数),我们在定义一个数mi为数组中的最小值,那么集合{f(2)Uf(3)....f(n)}就是我们想要的答案.f(x)=(a1/x)*(a2/x)*.....(ai/x),直接累加肯定…
B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/problem/B Description Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of ex…
题目连接:hdu_5213_Lucky 题意:给你n个数,一个K,m个询问,每个询问有l1,r1,l2,r2两个区间,让你选取两个数x,y,x,y的位置为xi,yi,满足l1<=xi<=r1,l2<=y2<=r2,使得x+y=K: 题解:首先,这题没有修改操作,即可以离线,离线区间问题就要想到莫队算法,然后看状态怎么搞,因为要求的答案满足区间的可加性,我们令f(l,r)表示 l到r这个区间满足条件的ans,令F(l1,r1,l2,r2)为在这两个区间内选取的数满足条件的ans,则根…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3556 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…
2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MB Submit: 7732  Solved: 3750 [Submit][Status][Discuss] Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 100%的数据满足:1≤n≤50000,1≤a≤b≤50000,1≤c≤d≤50000…
题目 一个有 \(N\) 个 元素的集合有 \(2^N\) 个不同子集(包含空集), 现在要在这 \(2^N\) 个集合中取出若干集合(至少一个), 使得它们的交集的元素个数为 \(K\) ,求取法的方案数,答案模 \(1000000007\) . \((1 \le N \le 10^6, 0 \le K \le N)\) 题解 又是一道 裸的 广义容斥定理 还没这道题难qwq 广义容斥定理 (二项式反演) : \[\displaystyle b_k = \sum_{i=k}^n \binom…
1284 2 3 5 7的倍数 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题   给出一个数N,求1至N中,有多少个数不是2 3 5 7的倍数. 例如N = 10,只有1不是2 3 5 7的倍数. Input 输入1个数N(1 <= N <= 10^18). Output 输出不是2 3 5 7的倍数的数共有多少. Input示例 10 Output示例 1经典的容斥定理,公式 |AUBUC|=|A|+|B|+|C|-|A^B|-|A^C|-|B^C|+|A…
1003 染色         Time Limit: 1sec    Memory Limit:256MB Description 今天离散数学课学了有关树的知识,god_v是个喜欢画画的人,所以他喜欢对于一棵树上色,且相邻节点不能染相同颜色,他有k种颜色,他希望他染色完后,这棵树上每种颜色都有,他想请教你有多少种染色方案?由于方案数过大,输出对1e9+7取模的结果. Input 第一行 n,k表示树的节点和颜色数量(1<=k<=n<=100000) 第二行 n-1个数字,第i个数字表…
n*m的矩形 k个人 第一行,最后一行,第一列,最后一列都至少站有一个人 小水题 正着做不好做,要反着想,那就容斥定理,ABCD四种情况分别是那四个行列分别没有人. #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> using namespace std; ; ; ][]; int main() { //freopen("a.in","…
Description As we all know caterpillars love to eat leaves. Usually, a caterpillar sits on leaf, eats as much of it as it can (or wants), then stretches out to its full length to reach a new leaf with its front end, and finally "hops" to it by c…
20180604 给出一个数N,求1至N中,有多少个数不是2 3 5 7的倍数. 例如N = 10,只有1不是2 3 5 7的倍数. Input 输入1个数N(1 <= N <= 10^18). Output 输出不是2 3 5 7的倍数的数共有多少. Sample Input 10 Sample Output 1 思路: ⒈如果对数学不是很了解,这道题可以按照常规思路来,只是分得不完,毕竟数据太大会爆掉.(20道测试过了7道) #include<cstdio> #include&…
When ?? was born, seven crows flew in and stopped beside him. In its childhood, ?? had been unfortunately fall into the sea. While it was dying, seven dolphins arched its body and sent it back to the shore. It is said that ?? used to surrounded by 7…
描述 给一个整数N,请你求出以N为分母的最简(既约)真分数中第K小的是多少? 输入 两个整数N个K. 对于30%的数据,1 <= N <= 1000000 对于100%的数据,1 <= N <= 10000000000 且 1 <= K <= φ(N).其中φ(N)是欧拉函数,也即1~N中与N互质的数的个数. 输出 一个整数表示答案的分子 样例输入 100 10 样例输出 23 思路: 显然和欧拉函数关系不大...开始思路已经很接近了.分解质因子,然后二分1到Mid中与…