当前位置:网站首页>478. randomly generate points in a circle
478. randomly generate points in a circle
2022-06-10 00:00:00 【Julia point C】
478. Randomly generate points in a circle
Today's daily question is to randomly generate points in a circle , The difficulty is medium , The specific methods are as follows
- Scatter point samples in the circumscribed rectangle of the circle .
- If the sampled point is within a circle , return ; Otherwise, resample .
- Because every dimension of two dimensions is uniformly distributed , So the results are uniformly distributed .
class Solution {
private:
double r, x, y;
public:
Solution(double radius, double x_center, double y_center) {
r = radius;
x = x_center;
y = y_center;
}
vector<double> randPoint() {
while (1) {
double cx = 2 * r * rand() / RAND_MAX - r + x;
double cy = 2 * r * rand() / RAND_MAX - r + y;
if ((cx - x) * (cx - x) + (cy - y) * (cy - y) <= r * r)
return {
cx, cy};
}
}
};
边栏推荐
- 请教一个问题,pg有类似mysql server_id一样的实例唯一标识么?
- 打破那面镜子,做回真正的自己(深度好文)
- Two tower model: Ernie gram pre training and fine-tuning matching
- Exness: twitter said that it would continue to share data with musk and conduct shareholder voting at the end of July or early August
- 没有项目管理经验,可以参加PMP考试?
- 堆叠线缆的光模块与普通光模块区别
- 我服了,MySQL表500W行,居然有人不做分区?
- C# WPF 实现Tab页动态增减
- 不用 if (obj != null) 判空
- 2022年质量员-市政方向-通用基础(质量员)考试练习题及模拟考试
猜你喜欢

ArcMap解决几何错误

哨兵3(Sentinel-3)数据简介

Simulated annealing-n queen problem

手推单精度浮点类型

荐书 | 即使是来自星星的你,我也想去靠近

黄希庭:心理学的研究要走中国人自己的道路,要做中国化的心理学研究

Online JSON to CSV tool

iOS 缓存 -- NSCache和沙盒缓存

Huangxiting: psychological research should follow the path of the Chinese people, and should do psychological research with Chinese characteristics

DDD driven domain design learning notes
随机推荐
模型部署简述
设计千万级学生管理系统的考试试卷存储方案
This configuration section cannot be used in this path. If the section is locked at the parent level, the solution to this situation will occur
消息队列的精髓与灵魂
你了解单例模式吗?反正我不了解。
On how enterprise we media can stand out
片上变化(on chip variation,OCV)概念学习
手推单精度浮点类型
CSRF/XSRF简介
Introduction to csrf/xsrf
The latest activity openharmony open source developer growth plan solution student challenge is about to start!
2022爱分析· 隐私计算厂商全景报告 | 爱分析报告
C# WPF后台动态添加控件(经典)
Sparksql source code series | to understand the distribution source code system (spark3.2)
Book club recruits | let's read "Mr. toad goes to see a psychologist"
Exness: twitter said that it would continue to share data with musk and conduct shareholder voting at the end of July or early August
“当你不再是程序员,很多事会脱离掌控”—— 对话全球最大独立开源公司SUSE CTO
Implementation of ngnix dynamic reading environment variables
2022年金属非金属矿山爆破考试题库及答案
poi 导出excel实战