ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

SZTUOJ 1121 - The Area of a Sector

2021-06-11 20:03:50  阅读:203  来源: 互联网

标签:Sector lf% p1 frac Area 1121 p2 double theta


SZTUOJ 1013 - The Area of a Sector

Description

Given a circle and two points on it, calculate the area of the sector with its central angle no more than 180 degrees.

Input

There are multiple test cases.
Each line contains 6 float numbers denote the center of the circle xc, yc, the two points on the circle x1, y1 and x2, y2.
1 <= xc, yc, x1, y1, x2, y2 <= 10000.

Output

The area of the sector. The result should be accurated to three decimal places.

Sample Input

0 0 1 1 -1 1
2.5 2.5 3.25 3.5 3.5 3.25

Sample Output

1.571
0.222

Hint

With math.h, you could define pi (3.1415926...) as const double pi = acos(-1.0);
Inverse trigonometric function could be obtained by acos, atan, asin, etc..
Be careful that angles like pi in C/C++ are in 3.1415926... type rather than 180.
You’d better use double instead of float. Load double with "%lf" but output it with "%f".

Source

2021 SZTU AI Class Qualifying.


思路分析

这道题来自2021伦琴AI班选拔机试C题,当时只有包括我在内的两个人做了出来。但题目本身并不难,根据描述按步编写即可。

本题需要求解扇形面积。根据圆的面积公式,我们可以推导出半径为\(r\),圆心角为\(\theta\)的扇形面积公式:

\[S_\theta=\frac{\theta}{2}r^2\ (0<\theta\leq2\pi) \]

根据上述公式,我们了解到,若想求解扇形面积,需要先求出扇形半径\(r\)和圆心角\(\theta\).

根据输入数据\(O(x_0,y_0),P_1(x_1,y_1),P_2(x_2,y_2)\),我们可以计算出半径和弦长的欧氏距离:

\[r=\sqrt{(x_0-x_1)^2+(y_0-y_1)^2}\\ l=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2} \]

作\(\triangle OP_1P_2\)的中垂线,根据几何性质,有:

\[\sin{\frac{1}{2}\angle O}=\sin{\frac{\theta}{2}}=\frac{l}{2r} \]

即:

\[\theta=2\arcsin{\frac{l}{2r}} \]

至此,求解面积所需的全部参量已经求出,带入扇形面积公式即可得解。


代码实现

// Language: C
#include<stdio.h>
#include<math.h>

typedef struct Point{
    double x;
    double y;
}point;

int main() {
    point o, p1, p2;
    double ox, oy, x1, y1, x2, y2;
    while (scanf("%lf%lf%lf%lf%lf%lf", &o.x, &o.y, &p1.x, &p1.y, &p2.x, &p2.y) != EOF) {
        double r = hypot(p1.x - o.x, p1.y - o.y);
        double l = hypot(p1.x - p2.x, p1.y - p2.y);
        double theta = 2 * asin(0.5 * l / r);
        printf("%.3f\n", r * r * theta / 2);
    }
    return 0;
}

标签:Sector,lf%,p1,frac,Area,1121,p2,double,theta
来源: https://www.cnblogs.com/ikaroinory/p/14788001.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有