CF 230 div2 C(圆内整点数)

C. Blocked Points
time limit per test
 2 seconds
memory limit per test
 256 megabytes
input
 standard input
output
 standard output

Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if:

  • the Euclidean distance between A and B is one unit and neither A nor B is blocked;
  • or there is some integral point C, such that A is 4-connected with C, and C is 4-connected with B.

Let's assume that the plane doesn't contain blocked points. Consider all the integral points of the plane whose Euclidean distance from the origin is no more than n, we'll name these points special. Chubby Yang wants to get the following property: no special point is 4-connected to some non-special point. To get the property she can pick some integral points of the plane and make them blocked. What is the minimum number of points she needs to pick?

Input

The first line contains an integer n (0 ≤ n ≤ 4·107).

Output

Print a single integer — the minimum number of points that should be blocked.

Sample test(s)
input
1
output
4
input
2
output
8
input
3
output
16


题解

首先,请允许我对那些牛逼的找规律帝们进行一番可耻的鄙视!

好吧我们来翻译一下题目意思。大概是讲,有一个在二维平面上的整数点之间的性质,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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值