当前位置:网站首页>LeetCode 2249. 统计圆内格点数目
LeetCode 2249. 统计圆内格点数目
2022-07-17 12:48:00 【Michael阿明】
1. 题目
给你一个二维整数数组 circles ,其中 circles[i] = [xi, yi, ri] 表示网格上圆心为 (xi, yi) 且半径为 ri 的第 i 个圆,返回出现在 至少一个 圆内的 格点数目 。
注意:
格点 是指整数坐标对应的点。
圆周上的点 也被视为出现在圆内的点。
示例 1:
输入:circles = [[2,2,1]]
输出:5
解释:
给定的圆如上图所示。
出现在圆内的格点为 (1, 2)、(2, 1)、(2, 2)、(2, 3) 和 (3, 2),在图中用绿色标识。
像 (1, 1) 和 (1, 3) 这样用红色标识的点,并未出现在圆内。
因此,出现在至少一个圆内的格点数目是 5 。
示例 2:
输入:circles = [[2,2,2],[3,4,1]]
输出:16
解释:
给定的圆如上图所示。
共有 16 个格点出现在至少一个圆内。
其中部分点的坐标是 (0, 2)、(2, 0)、(2, 4)、(3, 2) 和 (4, 4) 。
提示:
1 <= circles.length <= 200
circles[i].length == 3
1 <= xi, yi <= 100
1 <= ri <= min(xi, yi)
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/count-lattice-points-inside-a-circle
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
2. 解题
class Solution:
def countLatticePoints(self, circles: List[List[int]]) -> int:
X = max(x+r for x,y,r in circles) # 最大的边界
Y = max(y+r for x,y,r in circles) # 最大的边界
ans = 0
circles.sort(key=lambda x: x[-1], reverse=True) # 半径大的先找
for x in range(X+1):
for y in range(Y+1):
for x0, y0, r in circles:
if (x-x0)*(x-x0) + (y-y0)*(y-y0) <= r*r:
ans += 1
break
return ans
872 ms 14.9 MB Python3
我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号(Michael阿明),一起加油、一起学习进步!
边栏推荐
- C serialport configuration and attribute understanding
- [Acwing] 第 60 场周赛 C-AcWing 4496. 吃水果
- 从预测到决策,九章云极DataCanvas推出YLearn因果学习开源项目
- How to use SVG to make text effects arranged along any path
- B. Accuratelee [double pointer] [substr function]
- Virtual CPU and memory in yarn (CDH)
- unity3d如何利用asset store下载一些有用的资源包
- Analysis of the "Cyberspace Security" competition of Hunan secondary vocational group in 2022 (super detailed)
- HCIA 静态综合实验报告 7.10
- HCIA OSPF
猜你喜欢

Distinction between private key and public key -- Explanation of private key and public key
![高效理解 FreeSql WhereDynamicFilter,深入了解设计初衷[.NET ORM]](/img/cb/76200539c59bb865e60e5ea1121feb.png)
高效理解 FreeSql WhereDynamicFilter,深入了解设计初衷[.NET ORM]

yarn(cdh)中的虚拟cpu和内存

华为防火墙(NGFW)的双机热备

Zhongke Panyun - Cyberspace Security packet capture topic b.pcap

查找——平衡二叉树

Stream流

Smart Lang: VMware fixed virtual machine IP address

Analysis of Web Remote Code Execution Vulnerability of Zhongke panyun-d module

opencv 画黑色矩形,并写上序号
随机推荐
微信小程序云开发 1 - 数据库
Effectively understand FreeSQL wheredynamicfilter and deeply understand the original design intention [.net orm]
Studio 3T无限试用
YARN环境中应用程序JAR包冲突问题的分析及解决
【CSP-J 2021】总结
Develop the first Flink app
SAP S4 Material Management 库存模块 MARD 数据库表读取技术细节介绍
koa2 连接 mysql 数据库实现增删改查操作
C语言结构体实现简易通讯录
String类型函数传递问题
HCIA review and answer 2022.7.6
Distinction between private key and public key -- Explanation of private key and public key
TS解决引入插件的类型文件不存在的问题
Job: enter an odd number of 1-100
Autojs learning - multi function treasure chest - bottom
欧拉角,轴角,四元数与旋转矩阵详解
CPU负载与CPU使用率之区别
移植吴恩达深度学习01机器学习和神经网络第二周神经网络基础编程作业选修作业到pycharm
Through middle order traversal and pre order traversal, the subsequent traversal will always build a binary tree
Smart Lang: VMware fixed virtual machine IP address