1 :eye: > 100 :ear:

시간 제한6초메모리 제한2048 MB

요약
꼭짓점이 1000개씩인 두 단순 다각형이 주어질 때 두 다각형의 민코프스키 합의 넓이를 구한다.
난이도

어려움10점 중 9점

유형
기하, 분할 정복, 정렬, 구현
정답자
아직 제출이 없습니다

문제

Ever wondered how to generate a "random" non-convex polygon? One way to do it is ifsmirnov's algorithm. You can read about it here: https://codeforces.com/blog/entry/63058#comment-472683. It is also explained below:

Let nn be the number of vertices in the polygon. We randomly generate nn points p_1,p_2…,p_np\_1, p\_2 \ldots, p\_n inside the square \[0–105]×\[0–105]\[0\text{--}10^5] \times \[0\text{--}10^5] in this way:

  • for each point, we choose xx and yy from the uniform distribution of integers between 00 and 10510^5;
  • if the current point lies on some line formed by two other points among the previous ones, its coordinates are generated again until it doesn't lie on any such line.

After that, we build a minimum spanning tree for these points and traverse that tree in a depth-first order; when we visit a vertex for the first time, we write down its number. This sequence of numbers represents some Hamiltonian cycle over the points.

Next, we draw a segment between each consecutive pair of points in that cycle. While there are at least two intersecting segments, we fix this intersection by swapping the segments' ends: if the intersecting segments are formed by points p_i,p_i+1p\_i, p\_{i+1} and p_j,p_j+1p\_j, p\_{j+1}, then erase these segments and draw a segment between p_ip\_i and p_jp\_j and a segment between p_i+1p\_{i+1} and p_j+1p\_{j+1}. It's believed this procedure will eventually stop.

You can download the generator source code to generate some samples locally. To do that, download the archive using the "Download problem statement" link in the Yandex.Contest system between the statement and the submit form for this problem.

There, you will find the files gen.cpp and jngen.h. Run the following commands:

  • g++ gen.cpp -o gen
  • ./gen -n 1000 <seed>

The parameter <seed> may contain digits, letters, spaces, and some punctuation marks.

The problem itself is as follows. You are given two non-convex polygons; both are generated with ifsmirnov's algorithm. Find the area of their Minkowski sum.

The Minkowski sum of two polygons is defined as follows: if a point (x_1,y_1)(x\_1, y\_1) lies inside the first polygon or on its boundary, and a point (x_2,y_2)(x\_2, y\_2) lies inside the second polygon or on its boundary, then the point (x_1+x_2,y_1+y_2)(x\_1+x\_2, y\_1+y\_2) belongs to their Minkowski sum.

입력

The first line contains a single integer nn (n=103n = 10^3): the amount of vertices in the first polygon. The next nn lines contain the coordinates x_i,y_ix\_i, y\_i of its points (0≤x_i,y_i≤1050 \le x\_i, y\_i \le 10^5) in the order of traversal (clockwise or counter-clockwise).

The next line contains a single integer mm (m=103m = 10^3): the amount of vertices in the second polygon. The next mm lines contain the coordinates x_i,y_ix\_i, y\_i of its points (0≤x_i,y_i≤1050 \le x\_i, y\_i \le 10^5) in the order of traversal (clockwise or counter-clockwise).

Each of the polygons is non-convex, doesn't have self-intersections, and doesn't contain any three points lying on the same line.

출력

Output one number, the area of the two polygons' Minkowski sum. Your answer will be considered correct if its relative error does not exceed 10−410^{-4}.

힌트

Just to be sure, the sample starts with:

1000
28481 58236
26391 26391
33364 59290
...

예제1

  1. 예제 1

    입력
    ./gen -n 1000 sample
    
    예상 출력
    38851658799.3