PKU 3675 Telescope
来源:互联网 发布:有益网络 编辑:程序博客网 时间:2024/06/07 17:46
Telescope
Description
Updog is watching a plane object with a telescope. The field of vision in the telescope can be described as a circle. The center is at the origin and the radius isR. The object can be seen as a simple polygon ofN vertexes. Updog wants to know the area of the part of the object that can be seen in the telescope.
Input
The input will contain several test cases. For each case:
The first line contains only one real number R.
The second line contains an integer N. The following N lines contain two real numbersxi andyi each, which describe the coordinates of a vertex. Two vertexes in adjacent lines are also adjacent on the polygon.
Constraints: 3 ≤ N ≤50, 0.1 ≤ R ≤1000, -1000 ≤ xi,yi ≤ 1000
Output
For each test case, output one real number on a separate line, which is the area of the part that can be seen. The result should be rounded to two decimal places.
Sample Input
1030 2010 0-10 0
Sample Output
144.35
Source
#include <iostream>#include <cmath>using namespace std;#define MAXI 0x400#define sq(x) ((x) * (x))#define sng(x) (x == 0.0? 0.0: (x > 0? 1.0: -1.0))#define fmax(x, y) (x > y? x: y)#define fmin(x, y) (x < y? x: y)struct pt { double x, y;pt(double a = 0, double b = 0){x = a;y = b;}double len() { return sqrt(sq(x) + sq(y)); }double operator * (pt o) { return x * o.y - o.x * y; }double operator % (pt o) { return x * o.x + y * o.y; }} ps[MAXI];struct sg { pt a, b;double A, B, C;sg(pt x, pt y){a = x;b = y;A = a.y - b.y;B = b.x - a.x;C = -(a.y * B + a.x * A);}bool ons(pt o) {if (fmin(a.x, b.x) <= o.x && o.x <= fmax(a.x, b.x))if (fmin(a.y, b.y) <= o.y && o.y <= fmax(a.y, b.y))return 1;return 0;}double len() { return sqrt(sq(a.x - b.x) + sq(a.y - b.y)); }double ang() { return acos((a % b) / (a.len() * b.len())); }pt inr(sg o){double d = (A * o.B - o.A * B);double x = B * o.C - o.B * C;double y = A * o.C - o.A * C;return pt(x / d, -y / d);}};double r;int n;double TGL(pt a, pt b) //Triangulate{double sn = sng(a * b);if (a.len() < b.len()) swap(a ,b);pt lp(a.x - b.x, a.y - b.y), np(-lp.y, lp.x), cp;sg l(a, b), nl(pt(0, 0), np);pt tp = l.inr(nl);double tsu = 0;double oa = a.len();double ob = b.len();double ol = tp.len();;double ang, d;if (oa == 0.0 || oa == 0.0 || ol == 0.0)return 0.0;if (oa <= r && ob <= r){tsu += fabs(a * b / 2.0);}else if (oa > r && ob <= r){d = sqrt(sq(r) - sq(tp.len())) / l.len();tp = pt(tp.x + lp.x * d, tp.y + lp.y * d);ang = sg(a, tp).ang();tsu += ang * sq(r) / 2.0;tsu += fabs(tp * b/ 2.0);}else{ang = acos(ol / r);tsu += l.ang() * sq(r) / 2.0;if (oa > r && ob > r && ol < r && l.ons(tp))tsu += ol * r * sin(ang) - ang * sq(r);}return tsu * sn;}int main(){int i;double tsu;while (scanf("%lf", &r) != EOF){scanf("%d", &n);for (i = 0; i < n; i++)scanf("%lf%lf", &ps[i].x, &ps[i].y);tsu = 0.0;for (i = 0; i < n; i++)tsu += TGL(ps[i], ps[(i + 1) % n]);printf("%.2lf\n", fabs(tsu));}return 0;}
- PKU 3675 Telescope
- POJ 3675 Telescope
- POJ 3675 Telescope
- POJ 3675 Telescope(计算几何)
- poj 3675 Telescope 圆和多边形的公共面积
- 【UVA1543】Telescope
- Telescope UVA
- poj 3675 Telescope(三角剖分求多边形和圆交面积)
- POJ 3675/2986(Telescope/A Triangle and a Circle-三角形与圆的面积并)
- Chronometer and Telescope Links
- ZOJ 1679 Telescope (DP)
- POJ3675 Telescope(计算几何)
- UVA 1543 Telescope
- uva 1543 Telescope
- Cassegrain and Gregorian telescope
- uva 1543 - Telescope(dp+几何)
- UVA - 1543 Telescope dp+几何
- UVA 1543 - Telescope(dp+几何)
- 关键字__declspec概述
- 是goal还是phase?Maven插件(plugin)goal的执行与生命周期(lifecycle)phase的关系
- 根据NSArray里边的Object的某个属性进行排序
- 用Socket读取网页,但是经常出现错误
- strftime()函数详解
- PKU 3675 Telescope
- windows进程、线程和作业的基本了解
- 调用外部DLL,如:DelphiC++Java的DLL的调用方法,给出代码片段?
- 取得屏幕的宽高的问题
- buf 经典使用
- 解决出现的警告:Warning - secret file /etc/ppp/pap-secrets has world and/or group access Warning - secret fi
- [转] 80后的80条幽默有哲理的语录
- Linux中缺少so文件的问题
- c#中实现打印指定页(特定页), 附原代码