HDU-2841 Visible Trees(莫比乌斯反演)】的更多相关文章

题目连接: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…
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…
Visible Trees 传送门 解题思路: 实际上的答案就是1~n与1~m之间互质的数的对数,写出式子就是 \(ans=\sum^{n}_{i=1}\sum^{m}_{j=1}[gcd(i,j)=1]\) 由莫比乌斯反演引理 \(\sum_{d|n}\mu(d)=\epsilon(n)=[n=1]\)将\(\epsilon(n)\)替换为\([gcd(i,j)=1]\)有 \(\sum_{d|gcd(i,j)}\mu(d)=[gcd(i,j)=1]\) \(ans=\sum^{n}_{i=1…
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…
标题效果:给你个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…
/** 大意: 求[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…
题意:有一块(1,1)到(m,n)的地,从(0,0)看能看到几块(如果两块地到看的地方三点一线,后面的地都看不到). 思路:一开始是想不到容斥...后来发现被遮住的地都有一个特点,若(a,b)有gcd(a,b)!= 1,那么就会被遮住.因为斜率k一样,后面的点会被遮住,如果有gcd,那么除一下就会变成gcd = 1的那个点的斜率了.所以问题转化为求gcd不为1有几个点,固定一个点,然后容斥. #include<set> #include<map> #include<queue…
$n,m <= 1e5$ ,$i<=n$,$j<=m$,求$(i⊥j)$对数 /** @Date : 2017-09-26 23:01:05 * @FileName: HDU 2841 容斥 或 反演.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : $Id$ */ #include <bits/stdc++.h…