题解
首先,请允许我对那些牛逼的找规律帝们进行一番可耻的鄙视!
好吧我们来翻译一下题目意思。大概是讲,有一个在二维平面上的整数点之间的性质,4连通性,姑且这么说吧。有如下判定定理:
1.两个整数点的欧氏距离为1;
2.A与C连通,C与B连通,则A与B连通。
然后告诉你一个范围n,求这个范围下的从范围n开始,到原点方向所有的四连通点的个数。
这个问题抽象出来就是很著名的圆内整点问题。
这里有个连接,讲的是一般性O(n)算法,点我传送门
这里同样有一个数列资料,讲的是圆内整点数列,点我传送门
但是显然这样会超时的,因为O(n)的算法,时间肯定会超,这个时候就需要拼人品了!
请看这里,点我传送门
我在推导的时候,和大家一样,只是注意了他们都是4的倍数,却忽略了本质=。=
说白了就是:你丫的当时除个4多好!
可能有人会问为什么这个n乘根号2和我们的这个题有这么大关系,我觉得答案在这里:点我传送门
我们看到
高斯发现了这个规律,也就是初步的拟合结果,但是我们要求的是
好吧,其实这个根本毫无关系。
让我们这样想:
最下面和最上面的都好说,中间的其实就是满足
当然这里有个瑕疵,那就是我把两个三角形最尖端的地方分类错了,不要在意。。。
然后我们就可以发现,只计算一次坐标轴上的点,每一个象限内的点的分布满足数列0, 1, 2, 4, 5, 7, 8, 9, 11, 12, 14, 15, ...
oh no!答案不会是这个乘四吧!
特判n=0,计算公式:
/****
*@PoloShen
*Title:C
*/
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
while (cin >> n){
int x = n * sqrt(double(2));
if (n == 0) cout << 1 << endl;
else cout << x * 4 << endl;
}
return 0;
}