boj 75

本文介绍了一个关于计算火焰圈破坏特定区域内石板数量的问题。输入火焰圈的半径,程序将输出被火焰至少触及两个点的石板总数。通过数学几何的方法解决了此问题,并提供了一段C++实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Description
Lich Sandro investigates the magic of fire. He is standing in the center of a huge square hall with floor space one million square kilometers. The floor of the hall is paved with square 1 × 1 meter stone slabs. When Sandro waves his staff, a fire circle of radius R meters springs up around him. The center of the circle coincides with the center of the hall and is located at the point of contact of four slabs. Sandro wants to calculate the number of slabs damaged by the fire. A slab is assumed to be damaged if it has at least two common points with the fire circle. The figure shows as an example the slabs damaged by the fire circle of radius 4:
Problem illustration
 

Input

The input file contains multiple cases. Proceed until End Of File.

Each case contains the radius of the fire circle R > 0. This is an integer not exceeding 105.

 

Output

Output the number of damaged slabs.
 
Sample Input
2
4
 
Sample Output
16
60
 
Hint:
Category: Geometry?
The max int value is about 2*10^9.
Such tip will never appear in formal Preliminary and Final games.

 

代码:

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
	long long r;
	while(~scanf("%lld",&r))
	{
		long long sum = 0;
		long long r1 = r*r;
		for(long long i=r-1;i>=0;i--)
		{
			long long r2 = r1-i*i;
			double len = sqrt((double)r2);
			sum+=(long long)ceil(len);
		}
		printf("%lld\n",sum*4);
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值