ZOJ 3435 Ideal Puzzle Bobble (莫比乌斯反演基础题)
2015-08-24 18:25
363 查看
Ideal Puzzle Bobble
Time Limit: 2 Seconds Memory Limit:
65536 KB
Have you ever played Puzzle Bobble, a very famous PC game? In this game, as a very cute bobble dragon, you must keep shooting powerful bubbles to crush all the colorful bubbles upwards. Victory comes when all the bubbles upwards
are crushed.
Little Tom is crazy about this game. One day, he finds that all kinds of Puzzle Bobble are 2D Games. To be more excited when playing this game, he comes up with a new idea to design a 3D Puzzle Bobble game! In this game, the
bobble dragon is standing in a cubic room with L in length, W in width andH in height. Around him are so many colorful bubbles. We can use 3D Cartesian coordinates (x,y,
z) to represent the locations of the bobble dragon and those bubbles. All these coordinates (x,y,
z) are triple positive integers ranged from (1, 1,
1) to (L, W, H).
To simplify the problem, let's assume the bobble dragon is standing at (1,1,
1) in the room. And there is one colorful bubble at every (x,y,
z) in the room except (1, 1, 1). The dragon is so strong that he can shoot out a magical bubble to crushall the colorful bubbles in the straight line which the magical bubble flies every single time. Note
that bubbles aresignificantly small with respect to the distances between each two bubbles. Our question remains, how many magical bubbles will the cute dragon shoot before crushing all the colorful bubbles around him?
![](http://acm.zju.edu.cn/onlinejudge/showImage.do?name=puzzle_bobble.png)
W and H (2 ≤ L, W, H ≤ 1000000) which describes the size of the room. Proceed to the end of the file.
Author: ZHU, Yuke
Contest: ZOJ Monthly, November 2010
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3435
题目大意:(1,1,1)和(l, w, h)组成的长方体中从点(1,1,1)能看到的点数
题目分析:和前一题几乎一样,唯一的不同就是gcd(a, b, c) = 1,1 <= a <= l,1 <= b <= w,1 <= c <= h,范围不同,然而这并没有什么卵关系,l,w,h都减1,函数的参数变一下就行了
Time Limit: 2 Seconds Memory Limit:
65536 KB
Have you ever played Puzzle Bobble, a very famous PC game? In this game, as a very cute bobble dragon, you must keep shooting powerful bubbles to crush all the colorful bubbles upwards. Victory comes when all the bubbles upwards
are crushed.
Little Tom is crazy about this game. One day, he finds that all kinds of Puzzle Bobble are 2D Games. To be more excited when playing this game, he comes up with a new idea to design a 3D Puzzle Bobble game! In this game, the
bobble dragon is standing in a cubic room with L in length, W in width andH in height. Around him are so many colorful bubbles. We can use 3D Cartesian coordinates (x,y,
z) to represent the locations of the bobble dragon and those bubbles. All these coordinates (x,y,
z) are triple positive integers ranged from (1, 1,
1) to (L, W, H).
To simplify the problem, let's assume the bobble dragon is standing at (1,1,
1) in the room. And there is one colorful bubble at every (x,y,
z) in the room except (1, 1, 1). The dragon is so strong that he can shoot out a magical bubble to crushall the colorful bubbles in the straight line which the magical bubble flies every single time. Note
that bubbles aresignificantly small with respect to the distances between each two bubbles. Our question remains, how many magical bubbles will the cute dragon shoot before crushing all the colorful bubbles around him?
![](http://acm.zju.edu.cn/onlinejudge/showImage.do?name=puzzle_bobble.png)
Input
There are multiple cases, no more than 200. Each case contains one single line. In this line, there are three positive integersL,W and H (2 ≤ L, W, H ≤ 1000000) which describes the size of the room. Proceed to the end of the file.
Output
For each case, print the number of the magical bubbles needed to crush all the colorful bubbles in one line.Sample Input
2 2 2 3 3 3
Sample Output
7 19
Author: ZHU, Yuke
Contest: ZOJ Monthly, November 2010
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3435
题目大意:(1,1,1)和(l, w, h)组成的长方体中从点(1,1,1)能看到的点数
题目分析:和前一题几乎一样,唯一的不同就是gcd(a, b, c) = 1,1 <= a <= l,1 <= b <= w,1 <= c <= h,范围不同,然而这并没有什么卵关系,l,w,h都减1,函数的参数变一下就行了
#include <cstdio> #include <algorithm> #define ll long long using namespace std; int const MAX = 1000005; int mob[MAX], p[MAX], sum[MAX]; bool noprime[MAX]; int Min(int a, int b, int c) { return min(a, min(b, c)); } void Mobius() { int pnum = 0; mob[1] = 1; sum[1] = 1; for(int i = 2; i < MAX; i++) { if(!noprime[i]) { p[pnum ++] = i; mob[i] = -1; } for(int j = 0; j < pnum && i * p[j] < MAX; j++) { noprime[i * p[j]] = true; if(i % p[j] == 0) { mob[i * p[j]] = 0; break; } mob[i * p[j]] = -mob[i]; } sum[i] = sum[i - 1] + mob[i]; } } ll cal(int l, int r) { if(l > r) swap(l, r); ll ans = 0; for(int i = 1, last = 0; i <= l; i = last + 1) { last = min(l / (l / i), r / (r / i)); ans += (ll) (l / i) * (r / i) * (sum[last] - sum[i - 1]); } return ans; } ll cal(int l, int m, int r) { if(l > r) swap(l, r); if(l > m) swap(l, m); ll ans = 0; for(int i = 1, last = 0; i <= l; i = last + 1) { last = Min(l / (l / i), m / (m / i), r / (r / i)); ans += (ll) (l / i) * (m / i) * (r / i) * (sum[last] - sum[i - 1]); } return ans; } int main() { Mobius(); int a, b, c; while(scanf("%d %d %d", &a, &b, &c) != EOF) { a --; b --; c --; ll ans = 3; ans += (ll) cal(a, b, c); ans += (ll) cal(a, b); ans += (ll) cal(b, c); ans += (ll) cal(a, c); printf("%lld\n", ans); } }
相关文章推荐
- 范式的数据库具体解释
- php - mysql数据表的内容管理
- UVALive 5987
- java通过rJava调用R失败的问题总结
- 1090. Highest Price in Supply Chain (25) -计层的BFS改进
- CocoaPods安装和使用及问题:Setting up CocoaPods master repo
- Java 文件分块上传客户端源代码
- 1090. Highest Price in Supply Chain (25) -计层的BFS改进
- hdu 4302 Holedox Eating(优先队列/线段树)
- 最简单的HTML5游戏——贪吃蛇
- Java实现堆
- STL学习----入门(1)[unordered_map]
- AC+DP练习
- 运行hadoop程序遇到的一些问题及解决方案
- linux bash总结(二) 高级部分(适合初学者学习和非初学者参考)
- IOS7导航条与状态栏的那些事儿
- [转载]浅析Java中的final关键字
- 【数据库】E-R模型
- HDU 5015 233Matrix (构造矩阵)
- python 使用ioctl() 获得网卡IP 和MAC地址