mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
34 lines
1.3 KiB
HTML
34 lines
1.3 KiB
HTML
<p>给定圆的半径和圆心的位置,实现函数 <code>randPoint</code> ,在圆中产生均匀随机点。</p>
|
||
|
||
<p>实现 <code>Solution</code> 类:</p>
|
||
|
||
<ul>
|
||
<li><code>Solution(double radius, double x_center, double y_center)</code> 用圆的半径 <code>radius</code> 和圆心的位置<code> (x_center, y_center)</code> 初始化对象</li>
|
||
<li><code>randPoint()</code> 返回圆内的一个随机点。圆周上的一点被认为在圆内。答案作为数组返回 <code>[x, y]</code> 。</li>
|
||
</ul>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:
|
||
</strong>["Solution","randPoint","randPoint","randPoint"]
|
||
[[1.0, 0.0, 0.0], [], [], []]
|
||
<strong>输出: </strong>[null, [-0.02493, -0.38077], [0.82314, 0.38945], [0.36572, 0.17248]]
|
||
<strong>解释:</strong>
|
||
Solution solution = new Solution(1.0, 0.0, 0.0);
|
||
solution.randPoint ();//返回[-0.02493,-0.38077]
|
||
solution.randPoint ();//返回[0.82314,0.38945]
|
||
solution.randPoint ();//返回[0.36572,0.17248]</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>0 < radius <= 10<sup>8</sup></code></li>
|
||
<li><code>-10<sup>7</sup> <= x_center, y_center <= 10<sup>7</sup></code></li>
|
||
<li><code>randPoint</code> 最多被调用 <code>3 * 10<sup>4</sup></code> 次</li>
|
||
</ul>
|