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;
}