Area2Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1197 Accepted Submission (s): 278
Problem Description Tom was recently recruited as a pilot by the Air Force to participate in a practical exercise. The content of the drill is still bombing an island (this time the island is very large, very large, so how can a bomb be thrown completely on the Island ), it seems that Tom is indeed a pilot's life...
This time, the bomb that Xiao Bai threw was strange. The covered area of the explosion was not a circular shape, but an irregular simple polygon. Please help Xiao Bai again and calculate the area of the bomb.
It should be noted that this time, Tom threw two bombs in total, but the area of the public part of the two bombs can only be calculated once.
Input: first Input two numbers n and m, representing the number of vertices of the graphics covered by the explosion of the two bombs;
Then input n rows and one (x, y) Coordinate in each line to represent the vertices of the first bomb explosion range graph (given by the homeopathic needle or counter-clockwise ).
Finally, input m lines, and input a (x', y') Coordinate in each line, representing the vertex of the second bomb explosion range graph (given by the homeopathic needle or counterclockwise ).
(3 <= n, m <= 500)
Output outputs two decimal places, indicating the area of the actually bombed Island.
Sample Input
4 40 00 11 11 00.5 0.50.5 1.51.5 1.51.5 0.5
Sample Output
1.75
Given two polygon, calculate the sum of area
Resolve a Polygon into a triangle and calculate the area of the triangle.
Code:
/*************************************** * ******** Author: _ rabbitCreated Time: 2014/5/4 15: 03: 55 File Name: 20. cpp *************************************** * ********/# pragma comment (linker, "/STACK: 102400000,102400000") # include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; # define INF 10000000 # define eps 1e-8 # define pi acos (-1.0) typedef long ll; int dcmp (double x) {if (fabs (x)
0? 1:-1;} struct Point {double x, y; Point (double _ x = 0, double _ y = 0) {x = _ x; y = _ y ;}}; Point operator + (const Point & a, const Point & B) {return Point (. x + B. x,. y + B. y);} Point operator-(const Point & a, const Point & B) {return Point (. x-b.x,. y-b.y);} Point operator * (const Point & a, const double & p) {return Point (. x * p,. y * p);} Point operator/(const Point & a, const double & p) {return Point (. x/p,. y/p);} bool operator <(const Point & a, const Point & B) {return. x
= 0;} Point GetLineIntersection (Point p, Point v, Point q, Point w) {Point u = p-q; double t = Cross (w, u) /Cross (v, w); return p + v * t;} Point GetLineIntersection (Line a, Line B) {return GetLineIntersection (. p,. v, B. p, B. v);} vector
HPI (vector
L) {int n = L. size (); sort (L. begin (), L. end (); // sort all the Half Planes by the polar angle. Int first, last; vector
P (n); vector
Q (n); vector
Ans; q [first = last = 0] = L [0]; for (int I = 1; I
P) {int n = p. size (); double ans = 0; for (int I = 1; I
P1, p2; int main () {// freopen ("data. in "," r ", stdin); // freopen (" data. out "," w ", stdout); int n, m; while (~ Scanf ("% d", & n, & m) {Point pp; p1.clear (); p2.clear (); for (int I = 0; I
S1, s2; s1.push _ back (p1 [0]); s1.push _ back (p1 [I]); s1.push _ back (p1 [I + 1]); s2.push _ back (p2 [0]); s2.push _ back (p2 [j]); s2.push _ back (p2 [j + 1]); double r1, r2; int flag1, flag2; r1 = PolyArea (s1); if (dcmp (r1)> = 0) flag1 = 1; else flag1 = 0; if (dcmp (r1) <0) reverse (s1.begin (), s1.end (); r2 = PolyArea (s2); if (dcmp (r2)> = 0) flag2 = 1; else flag2 = 0; if (dcmp (r2) <0) reverse (s2.begin (), s2.end (); vector
L; for (int k = 0; k <3; k ++) L. push_back (Line (s1 [k], s1 [(k + 1) % 3]-s1 [k]); for (int k = 0; k <3; k ++) L. push_back (Line (s2 [k], s2 [(k + 1) % 3]-s2 [k]); vector
Tt = HPI (L); if (flag1 = flag2) ret-= PolyArea (tt); else ret + = PolyArea (tt);} printf ("%. 2lf \ n ", ret);} return 0 ;}