[AHOI2017 Junior High School Group] cover

Topic link

Question background The
following is a simplified version of the question that does not affect the meaning of the question.

Title description
An n×n grid graph (labeled starting from 1) has m detectors, and each detector has a detection radius r. Ask how many of these n×n points can be detected.

Input format
3 integers n, m, r in the first line;

In the next m lines, two integers x and y in each line represent the coordinates of the i-th detector.

Output format
The number of points that can be detected.

Input and output example
Input #1
5 2 1
3 3
4 2
Output #1
8
Description/Prompt
1≤n,m≤100

Code:

#include<iostream>
#include<cmath>
using namespace std;
int num[123][123] = {
    
    0};
int main()
{
    
    
	int n, m, r, x, y, count = 0;
	cin >> n >> m >> r;
	while(m--)
	{
    
    
		cin >> x >> y;
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++)
			{
    
    
				double d = sqrt((x - i) * (x - i) + (y - j) * (y - j));	//两点间距离 
				if(d <= r) num[i][j]++;
			}
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			if(num[i][j] > 0) count++;
	cout << count;
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_44826711/article/details/113748017