UVA - 11014 Make a Crystal
来源:互联网 发布:淘宝店铺营销亮点 编辑:程序博客网 时间:2024/06/07 06:13
Description
Problem C
Make a Crystal
Input: Standard Input
Output: StandardOutput
A scientist is trying hard to make a very large crystal, a largecrystal of Carbon to be specific. He believes, as Diamond is a crystal ofCarbon and very precious, so his new crystal of carbon would be as precious asDiamond in the long run. The atoms in his crystal will not hold togethernaturally, so he wants to put a strong force at the center of the crystal,which will attract all the carbon atoms and keep them together.
The Carbon atoms in a diamond crystal can be considered to be placed ina cube (Shown inFigure2). The scientist alsowants to place the carbon atoms of his crystal in an(N x N x N) cube, whereN is an even number. If the center of thiscube is(0,0,0) and all the sides of this cube are parallel toxy,yz orxz planethen all the atoms will be placed in three-dimensional integer coordinates. Soif(x, y, z) is thecoordinate of an atom placed in an(N*N*N) cube thenx,y, and z are integers and (-N/2<=x, y,z<=N/2). Asthe strong force at the center will attract all the atoms so the atoms areplaced in such a way so that no atom is between the center and another atom.For example if there is an atom at coordinate(2, 2, 2) then no atoms should be placed incoordinate(1, 1, 1) asthen the atom at(1, 1, 1)will block the attractive force between(2, 2, 2) and the center. Similarly if there is anatom at place(1, 1, 1) then there should be no atom in location(2,2, 2).Figure 3 shows such an arrangement for(4x4x4) cube: if atoms are placed in all integercoordinates (the value ofx,y andz are integers) except those marked withblack circles, no atom will be between the center and another atom. Given thesize of the cube (length of one side) in which atoms are to be placed to makethe crystal, your job is to find out the maximum number of atoms that can beplaced following the constraints mentioned above
Input
The input file contains at most 30 lines of inputs. Each line contains an even integer N (0<N<=200000), which indicates the length of one side of the cube inwhich the scientist plans to put his atoms. Input is terminated by a line wherethe value of N is zero.
Output
For each lineof input except the last one produce one line of output. This line shouldcontain the serial of output followed by an integer, which denotes the maximumnumber of atoms that can be placed.
SampleInput Outputfor Sample Input
4
2
0
Crystal 1: 98
Crystal 2: 26
Problem setter: Shahriar Manzoor, EPS
Special Thanks: Derek Kisman,EPS
题意:一个N*N*N的立方体,坐标范围是-N/2<=x,y,z<=N/2,你的任务是选择尽量多的网格点,使得对于任意两个选出的P和Q,OPQ不共线,输出最大的点数
思路:设f(k)表示点(x,y,z)都是都是k的倍数的情况数,那么所有的情况就是f(1)了,然后处理共线的可能,但是在枚举k的过程可能会有重复计算,比如f(6)就会被f(2)和f(3)计算过,所以需要用到容斥原理,对于奇数个因子我们选择减,偶数个选择加,结果是:f(1) - f(2) - f(3) - f(5) - f(7) - ... + f(2*3) + f(2*5) + f(3*5) + ... - f(2*3*5) - f(2*3*7)...
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>typedef long long ll;using namespace std;const int maxn = 200005;ll n, prime[maxn];int vis[maxn], cnt;void init() {vis[1] = 1;cnt = 0;for (ll i = 2; i < maxn; i++) {if (vis[i])continue;prime[cnt++] = i;for (ll j = i*i; j < maxn; j += i)vis[j] = 1;}}ll pow3(ll x) {return x * x * x - 1;}int count(ll x) {int ans = 0;for (int i = 0; i < cnt && prime[i] <= x; i++) {if (!vis[x]) {ans++;break;}if (x % prime[i] == 0) {ans++;x /= prime[i];if (x % prime[i] == 0)return -1;}}return ans;}ll cal(ll x) {int cnt = count(x);if (cnt == -1)return 0;if (cnt & 1)return -pow3((n / 2 / x) * 2 + 1);else return pow3((n / 2 / x) * 2 + 1);}ll solve() {ll ans = pow3(n+1);for (ll i = 2; i <= n; i++)ans += cal(i);return ans;}int main() {init();int cas = 1;while (scanf("%lld", &n) != EOF && n) {printf("Crystal %d: %lld\n", cas++, solve());}return 0;}
- UVA - 11014 Make a Crystal
- UVa 11014 - Make a Crystal
- UVA 11014Make a Crystal
- uva 11014 - Make a Crystal(数论)
- UVA 11014 - Make a Crystal(容斥原理)
- Tips to choose a crystal
- Tips to choose a crystal
- uva 800 - Crystal Clear(几何)
- uva 10453 Make Palindrome
- UVA 10453 Make Palindrome
- UVA 10453 Make Palindrome
- UVA 10453 Make Palindrome
- UVA - 10453 Make Palindrome
- UVa:10453 Make Palindrome
- uva 10453 - Make Palindrome
- UVA 10453 - Make Palindrome
- UVA - 10453 Make Palindrome
- UVA - 10453 Make Palindrome
- 《TCP-IP详解卷1:协议》读书笔记四 ARP地址解析协议
- Spring @Resource、@Autowired、@Qualifier的注解注入及区别 .
- 漫漫编程路上学到的宝贵经验
- Linux Top 命令解析 比较详细
- 同为程序员 为什么我的工资最低
- UVA - 11014 Make a Crystal
- xampp 80 443端口冲突和MySQL Service detected with wrong path解决办法
- struts配置参数详解
- Linux学习笔记:虚拟机设置中的各种网络连接方式详解
- 【基于WinForm+Access局域网共享数据库的项目总结】之篇二:WinForm开发扇形图统计和Excel数据导出
- 看操作系统虚拟化原理总结篇——虚拟化概述原理
- Maven查找使用的包
- iphone手势识别(双击、捏、旋转、拖动、划动、长按)UITapGestureRecognizer
- opencv 图片基本处理(灰度化,反色,二值化,膨胀腐蚀以及ROI的copy等)