当前位置:网站首页>Programming exercises: whole point and circle (solution ideas and code implementation)
Programming exercises: whole point and circle (solution ideas and code implementation)
2022-06-30 14:40:00 【A cute little monkey】
【 Problem description 】
Given in a plane rectangular coordinate system n On the hour , Take each integral point as the center of the circle , Draw a radius of r The circle of , Please find out which integer point is the center of the circle and the circle contains the most integer points , Output this value .
【 Input form 】
Enter two integers on the first line n and r, Respectively represent the number of integral points and the value of radius
Next n Enter two integers per line x,y, They represent the abscissa and ordinate of the whole point respectively
【 Output form 】
Output in the given n Draw a radius of... For the center of the circle at a certain point in the whole point r The maximum number of integer points that can be contained in a circle of
【 The sample input 】
3 2
0 0
0 2
2 0
【 Sample output 】
3
【 Sample explanation 】
With (0,0) This point draws a radius for the center of the circle 2 The circle of , Can contain 3 A little bit
And then (0,2) or (2,0) Draw a radius for the center of the circle 2 The circle of , Can only contain 2 A little bit
Therefore, it can contain at most 3 On the hour
【 Standard for evaluation 】
about 100% The data of , Guarantee -1e9<=x,y<=1e9,1<=r<=2e9
about 40% The data of , Guarantee 1<=n<=100
about 100% The data of , Guarantee 1<=n<=5000
title
The data range of points is not large , Square enumeration can solve
Note that the calculated distance will explode int, Need to open long long Carry out operations
utilize pair Storing point coordinates is more intuitive
Code implementation
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef pair <long long , long long > PLL;
vector <PLL> s;
int n;
long long r;
int main()
{
cin >> n >> r;
for (int i = 0; i < n; i ++)
{
long long x, y;
cin >> x >> y;
s.push_back({
x, y});
}
int res = 0;
for (int i = 0; i < n; i ++)
{
int temp = 0;
for (int j = 0; j < n; j ++)
{
// Whether the integer operation will explode int
if((s[i].first - s[j].first) * (s[i].first - s[j].first) + (s[i].second - s[j].second) * (s[i].second - s[j].second) <= r * r)
{
temp ++;
}
}
res = max(res, temp);
}
cout << res;
return 0;
}
边栏推荐
- Minimum covering substring of two pointers
- [extensive reading of papers] analyzing connections between user attributes, images, and text
- Implement a long-click list pop-up box on apiccloud
- Laravel RBAC laravel permission use
- 数据恢复软件EasyRecovery15下载
- Zend studio how to import an existing project
- Vue returns to the previous page without refreshing the page / Vue caches the page
- [extensive reading of papers] attributes guided facial image completion
- PHP conditional operator
- 2021-05-12
猜你喜欢

Clear the route cache in Vue
![[buuctf] [geek challenge 2019] secret file](/img/00/23bebd013eb4035555c0057725e3c4.jpg)
[buuctf] [geek challenge 2019] secret file
![【BUUCTF】[GXYCTF2019]Ping Ping Ping1](/img/dc/4d87dfb0c2fa9cd75b54e092fd3971.jpg)
【BUUCTF】[GXYCTF2019]Ping Ping Ping1

Learn about data kinship JSON format design from sqlflow JSON format

PS cutting height 1px, Y-axis tiling background image problem

On simple code crawling Youdao translation_ 0's problem (to be solved)

Why does the folder appear open in another program

Ctfshow getting started with the web (ThinkPHP topic)

go time. after

DiceCTF - knock-knock
随机推荐
MySQL back to table query optimization
Wuenda 2022 machine learning special course evaluation is coming!
Use PHP to delete the specified text content in the file
Double pointer palindrome string
Lfi-rce without controllable documents
notepad正则删除关键词所在行
Hbuilder most commonly used and full shortcut key set
Why is the resolution of the image generated by PHP GD library 96? How to change it to 72
Go language mutex lock
V3 03_ Getting started
Larave8 JWT API expiration custom error return
Fastcgi CGI shallow understanding
Attack and defense world web questions
Querywrapper in mybaits plus
[buuctf] [actf2020 freshman competition]exec1
数据恢复软件EasyRecovery15下载
Detailed explanation of the first three passes of upload Labs
Notepad regular delete the line of the keyword
After the MySQL service on the local computer is started and stopped, some services will automatically stop when they are not used by other services or programs
DiceCTF - knock-knock