当前位置:网站首页>Acwing 4499. draw a circle (similar to a triangle)
Acwing 4499. draw a circle (similar to a triangle)
2022-07-24 02:50:00 【GHOSTANDBREAD】
Topic link :4499. A circle - AcWing Question bank
In a two-dimensional plane , Give one with (x1,y1)(x1,y1) For the center of a circle , The radius is RR And a coordinate of (x2,y2)(x2,y2) The point of .
Please draw a circle on the two-dimensional plane , requirement :
- There is no point satisfaction in the plane, not only on the circle you draw , And outside the given circle .
- The given point cannot be in the circle you draw ( Can be on a circle ).
- The area covered by the given circle and not covered by the circle you draw should be as small as possible .
Please output the center coordinates and radius of the circle you drew .
Input format
All in one line , contain 55 It's an integer R,x1,y1,x2,y2R,x1,y1,x2,y2.
Output format
Three real numbers xans,yans,rxans,yans,r, among (xans,yans)(xans,yans) Is the coordinate of the center of the circle you drew ,rr Is the radius of the circle you drew .
Keep the result to six decimal places .
Data range
All test points meet 1≤R≤1051≤R≤105,|x1|,|y1|,|x2|,|y2|≤105|x1|,|y1|,|x2|,|y2|≤105.
sample input 1:
5 3 3 1 1
sample output 1:
3.767767 3.767767 3.914214
sample input 2:
10 5 5 5 15
sample output 2:
5.000000 5.000000 10.000000Code :
#include<bits/stdc++.h> // Similar triangles
using namespace std;
#define endl "\n"
int main() {
ios::sync_with_stdio(false);
cout.tie(0);
double r, x1, x2, y1, y2;
cin >> r >> x1 >> y1 >> x2 >> y2;
if(sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) >= r) { // Outside the circle
cout << fixed << setprecision(6) << x1 << " " << y1 << " " << r;
} else { // In a circle
if(x1 == x2 && y1 == y2) { // In coincidence
double rr = r / 2.0;
x2 += rr;
cout << fixed << setprecision(6) << x2 << " " << y2 << " " << rr;
}
else { // When they don't coincide
double len = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
double rr = len + r;
rr /= 2.0;
x2 += rr * (x1 - x2) / len; // (x1 - x2) / len = cos
y2 += rr * (y1 - y2) / len; // (y1 - y2) / len = sin
cout << fixed << setprecision(6) << x2 << " " << y2 << " " << rr;
}
}
return 0;
}边栏推荐
- Correlation
- Jina AI and datawhale jointly launched a learning project!
- Honey, we are homeless now
- (六)装饰器扩展之[email protected]使用原理
- 日常杂谈(一)
- summernote富文本编辑器
- Go IO operation - file read
- Attack and defense world web practice area (backup, cookie, disabled_button)
- Dynamically set the navigationbartitletext of the applet
- Attack and defense world web practice area (weak_auth, simple_php, xff_referer)
猜你喜欢

Pyg uses messagepassing to build GCN to realize node classification

Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1

Take you into the world of MySQL mvcc
![JS when transferring parameters, the incoming string has data; No data when number is passed in; 2[0] is right! Number type data can be subscripted](/img/4e/3d0c25d9579b6d5c00473048dbbd83.png)
JS when transferring parameters, the incoming string has data; No data when number is passed in; 2[0] is right! Number type data can be subscripted
![[hdlbits questions] Verilog language (2) vectors](/img/eb/125c9a7781391dc53e37ce347a475d.png)
[hdlbits questions] Verilog language (2) vectors

Lcd1602——斌哥51

summernote富文本编辑器

508. The subtree element with the most occurrences and the pure C implementation of hash table method

O3DE 的Lumberyard 游戏引擎

Camper recruitment | AI youth with the world in mind, the United Nations needs your help for sustainable development!
随机推荐
[FPGA tutorial case 38] communication case 8 - serial parallel serial data transmission based on FPGA
Job hunting and recruitment system of SSM part-time job hunting
【HDLBits 刷题】Verilog Language(2)Vectors 部分
Fasterrcnn sample code test 1: make anchor_ generator = None
[interview: concurrent Article 21: multithreading: activeness] deadlock, livelock, hunger
To forge ahead on a new journey, the city chain science and technology carnival was grandly held in Xiamen
Understand the timing of loading classes into the JVM
Openresty Lua resty balancer dynamic load balancing
compostion-api(setup中) watch使用细节
Ugui source code analysis - imaskable
Summernote supports custom video upload function
c语言小练习
中城院真的在帮助供应商解决问题吗?
JpaRepository扩展接口
QT display Chinese garbled code
Symbol类型
Honey, we are homeless now
ssm的求职招聘系统兼职应聘求职
How to get gait energy map Gei
508. The subtree element with the most occurrences and the pure C implementation of hash table method