2021-06-05

该博客主要讨论了一个数学问题,即在1x1的网格上,将长度和宽度划分为50个部分,形成2500个单位网格。然后,给定n个半径为R的等径圆,求未被任何圆覆盖的单位网格数量。博客中提供了输入输出示例及解题代码,通过计算每个网格到圆心的距离来确定是否被覆盖,最终输出未被覆盖的网格总数。

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

									Grids
									On an 1 × 1 grid,partition the length and width into 50 parts,forming 2500 unit grids with the same size.Now,given n circles with equal radius R on the grid.Find the total number of unit grids which are not covered by any of a circle.

A unit grid is covered by a circle,means that the distance between the center of the unit grid and the center of circle is less or equal R.

输入

There will be multiple test cases.Each line of input contains a Integer n (1≤n≤100) and a decimal R (0.01≤R≤0.1).Follows n lines,each line describe the center of circle i,include two decimal xi, yi (0≤xi, yi≤1).

输出

For each test case output a line,output the number of the points which are not covered.

样例输入

1 0.02
0.03 0.03
1 0.10
0.952423 0.042419

样例输出

2495
2454

提示

The picture for the first sample input.

题解:

#include<bits/stdc++.h>
#include<algorithm>
#include<queue>
using namespace std;
typedef unsigned long long ll;
const int N=5e5+10;
const ll mod= 1e9+7;
struct node
{
	double x,y;
}h[105];
double sum=0;
int main()
{
   string s;
   int n;
   double r;
   while(cin>>n>>r)
   {
   	r*=100;
   	for(int i=0;i<n;i++)
   	{
   		cin>>h[i].x>>h[i].y;
   		h[i].x*=100;
   		h[i].y*=100;
	   }
	   int sum=0;
	   for(double  i=1;i<=100;i+=2)
	   {
	   for(double j=1;j<=100;j+=2)
	   {
	   	int f=0;
	   	for(int v=0;v<n;v++)
	   	{
	   		if(sqrt((i*1.00000-h[v].x)*(i*1.0-h[v].x)+(j*1.0-h[v].y)*(j*1.0-h[v].y))<=r)
	   		{
	   			f=1;
	   			break;
			   }
		   }
		   if(f)
		   sum++;
	   }
}
cout<<2500-sum<<endl;
	} 
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值