CF

来源:互联网 发布:最新网络名词英文 编辑:程序博客网 时间:2024/03/28 17:52

1.题目描述:

D. Volatile Kite
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a convex polygon P with n distinct vertices p1, p2, ..., pn. Vertex pi has coordinates (xi, yi) in the 2D plane. These vertices are listed in clockwise order.

You can choose a real number D and move each vertex of the polygon a distance of at most D from their original positions.

Find the maximum value of D such that no matter how you move the vertices, the polygon does not intersect itself and stays convex.

Input

The first line has one integer n (4 ≤ n ≤ 1 000) — the number of vertices.

The next n lines contain the coordinates of the vertices. Line i contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th vertex. These points are guaranteed to be given in clockwise order, and will form a strictly convex polygon (in particular, no three consecutive points lie on the same straight line).

Output

Print one real number D, which is the maximum real number such that no matter how you move the vertices, the polygon stays convex.

Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .

Examples
input
40 00 11 11 0
output
0.3535533906
input
65 010 012 -410 -85 -83 -4
output
1.0000000000
Note

Here is a picture of the first sample

Here is an example of making the polygon non-convex.

This is not an optimal solution, since the maximum distance we moved one point is  ≈ 0.4242640687, whereas we can make it non-convex by only moving each point a distance of at most  ≈ 0.3535533906.


2.题意概述:

给你一个凸多边形,然后要你求最大的D,使得所有的点分别沿着任意方向移动D,多边形仍然是凸多边形。

3.解题思路:

对于相邻三个点,考虑移动中间那个点,当移动到它们三点共线时候一定是一个临界条件D,那么O(N)的更新每个顶点的临界条件即可。

对于到临界条件D的计算用到了叉乘。对于向量AxB表示以A和B为边的平行四边形面积,然后再算出这个平行四边形的高就是顶点移动到三点共线所需要移动的最小距离D。

4.AC代码:

#include <bits/stdc++.h>#define INF 1e18#define maxn 100100#define lson root << 1#define rson root << 1 | 1#define lent (t[root].r - t[root].l + 1)#define lenl (t[lson].r - t[lson].l + 1)#define lenr (t[rson].r - t[rson].l + 1)#define N 1111#define eps 1e-6#define pi acos(-1.0)#define e exp(1.0)using namespace std;const int mod = 1e9 + 7;typedef long long ll;typedef unsigned long long ull;struct point{double x, y;point() {}point(double a, double b) { x = a; y = b; }friend point operator- (point a, point b){return point(a.x - b.x, a.y - b.y);}friend point operator+ (point a, point b){return point(a.x + b.x, a.y + b.y);}friend double operator* (point a, point b){return a.x * b.y - b.x * a.y;}} p[N];double getdis(point a, point b){return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}int main(){#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);long _begin_time = clock();#endifint n;while (~scanf("%d", &n)){for (int i = 0; i < n; i++)scanf("%lf%lf", &p[i].x, &p[i].y);for (int i = n; i < n + 2; i++)p[i] = p[i - n];double ans = INF;for (int i = 0; i < n; i++){double tmp = (p[i + 2] - p[i]) * (p[i + 1] - p[i]) / 2.0 / getdis(p[i + 2], p[i]);ans = min(ans, tmp);}printf("%.10f\n", ans);}#ifndef ONLINE_JUDGElong _end_time = clock();printf("time = %ld ms.", _end_time - _begin_time);#endifreturn 0;}

0 0
原创粉丝点击