hdu 2841 Visible Trees】的更多相关文章

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 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…
题目连接: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…
原文链接 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…
题意: m*n(1<=m,n<=100000)的森林里,起始点在(1,1),某人从(0,0)点开始看,问能看到多少棵树. 题解: 求出1~x中的每个数与1~y的数中互质的数的总和.用素数筛筛出1e5以内的素数.在用这些素数筛出1e5以内每个数的素数因子.最后通过容斥算出与每个数互质的个数. #include <iostream> #include <cstdio> #include <algorithm> #include <vector> #i…
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…