Gym - 101845D 计算几何

Ignacio is a famous mathematician, some time ago he was married with Dolly, a famous scientific, at that time they bought a huge piece of land that they would use to construct a national university, they chose the land with the following property: if someone walks straight from any place inside the land to any other place inside the land then all that path would be inside the land, that‘s because they wanted that people could go from any point of the university to another as fast as possible.

Sadly, today Ignacio and Dolly are getting divorced, so they need to divide the land in two parts, to be fair with this division Dolly will give to Ignacio a list consisting of many different pairs of corners of the land, because governmental laws only permit to divide a land using corners of that land. Then, after dolly makes the list Ignacio will choose one pair of corners from that list and then they will divide the land with a straight wall from one of the corners to the other, the area of this wall is zero. Finally, Dolly will take the part with the biggest area.

For example, the image below corresponds to a land with coordinates (0, 0), (1,-1), (3, -1), (4, 0), (4, 2), (3, 3), (1, 3) and (0, 2) in that order, then Dolly made a list with 3 options, for the first one she chose corners with indexes 2 and 5, for the second she chose corners 7 and 3 and for the last she chose corners 4 and 7. In each case the shaded area corresponds to the area that would correspond to Ignacio if he chooses that option from the list.

You are hired from Ignacio to help him see which is the maximum area possible of the land he can have.

Input

The first line of input contains 2 numbers n(3?≤?n?≤?105) and m(2?≤?m?≤?105) - the numbers of corners of the land and the number of pairs in the list of Dolly respectively

Next n lines follow, the i-th of these lines contains xi and yi (?-?108?≤?xi,?yi?≤?108) - the i-th coordinate of a corner from the land.

Finally, m lines follow, the i-th of these lines contains pi and qi (1?≤?pi,?qi?≤?n,?pi?≠?qi)
- the i-th pair of the corners in the list from dolly. It is guaranteed
that all pairs are different and that there are no 3 co-linear corners
in the land.

Output

Print a single number - the maximum area of the land that Ignacio could keep for himself.

You answer is considered correct, if its absolute or relative error does not exceed 10?-?4

Examples

Input

4 20 00 100100 100100 01 34 2

Output

5000.000000

Input

8 30 01 -13 -14 04 23 31 30 22 53 74 7

Output

7.000000

维护一下面积的前缀和即可;注意多边形面积的公式:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-4
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
	ll x = 0;
	char c = getchar();
	bool f = false;
	while (!isdigit(c)) {
		if (c == ‘-‘) f = true;
		c = getchar();
	}
	while (isdigit(c)) {
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return f ? -x : x;
}

ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; }

/*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
	if (!b) {
		x = 1; y = 0; return a;
	}
	ans = exgcd(b, a%b, x, y);
	ll t = x; x = y; y = t - a / b * y;
	return ans;
}
*/

int n, m;
struct node {
	double x, y;
}pot[maxn];

double pre[maxn];
int main() {
	//   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++)rdlf(pot[i].x), rdlf(pot[i].y);
	for (int i = 1; i < n; i++) {
		pre[i] = pre[i - 1] + 1.0*(pot[i].x*pot[i + 1].y - pot[i + 1].x*pot[i].y);
	}
	double sum = fabs(pre[n - 1] - pot[1].x*pot[n].y + pot[n].x*pot[1].y) / 2.0;
	double maxx = -1.0*inf;
	while (m--) {
		int x, y; rdint(x); rdint(y);
		if (x > y)swap(x, y);
		double sum1 = fabs(pre[y - 1] - pre[x - 1] - pot[x].x*pot[y].y + pot[y].x*pot[x].y) / 2.0;
		maxx = max(maxx, min(sum1, sum - sum1));
	}
	printf("%.8lf\n", 1.0*maxx);
	return 0;
}


原文地址:https://www.cnblogs.com/zxyqzy/p/10300746.html

时间: 2024-10-12 19:56:41

Gym - 101845D 计算几何的相关文章

Gym 101055A 计算几何,暴力

http://codeforces.com/gym/101055/problem/A 题目:给定一些三维空间的点,要你找一个平面,能覆盖尽量多的点,只要求输出点数即可.n<=50 因为数据量小,我们考虑暴力. 首先,三个不在同一条直线的点,确定一个平面,然后枚举其他的点.判断一下,这样的复杂度是n^4.可以接受 特判.所有点都在同一条直线.直接输出n. 后面的,枚举三个点后,能算出这个平面的法向量,然后枚举其他点,与法向量的数量积是0的,就可以ans++ #include <cstdio>

Rasheda And The Zeriba Gym - 100283A ? 计算几何

http://codeforces.com/gym/100283/problem/A 考虑到多边形是不稳定的,是可以变来变去的. 那么总是可以把每个点放到圆上. 所以只需要判断圆心角是不是小于等于360即可. #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <assert.h>

Gym 101464C - 计算几何+二分(uva1463)

网络赛的A题.不是很难,但是我觉得对代码能力的要求还是挺高的. 注意模块化. 因为是浮点数,所以二分用的很多很多. 参考 https://blog.csdn.net/njupt_lyy/article/details/81256538?utm_source=blogxgwz4 对半径二分,这样我们只需要判断能不能放的下这个圆.这时,通过给定的半径,对于每一条线段可以找到一个区间(或者为空),使得圆心不能落在这个区间上,我们只需要判断区间的并集是否覆盖了[0,L].那么如何去找到这个区间呢?对于每

【计算几何】【分类讨论】Gym - 101173C - Convex Contour

注意等边三角形的上顶点是卡不到边界上的. 于是整个凸包分成三部分:左边的连续的三角形.中间的.右边的连续的三角形. 套个计算几何板子求个三角形顶点到圆的切线.三角形顶点到正方形左上角距离啥的就行了,分类比较多. #include<cstdio> #include<cmath> using namespace std; const double PI=acos(-1.0); int n; char a[25]; struct Point{ double x,y; double len

Gym 101917 E 简单计算几何,I 最大流

题目链接 https://codeforces.com/gym/101917 E 题意:给定一个多边形(n个点),然后逆时针旋转A度,然后对多边形进行规约,每个点的x规约到[0,w]范围内,y规约到[0,h]范围内,输出规约后的结果. 解析:求出来 多边形的长和宽,再和w,h比较,对点按比例进行缩放就好了. (多边形旋转其实是绕给出的第一个点旋转,以为是绕原点wa了1发). AC代码 1 #include <bits/stdc++.h> 2 #define Vector Point 3 usi

Codeforces GYM 100651 D I Conduit! (水计算几何)

大致题意: 1e3 个线段,画在一张纸上,求可以看成多少个线段,( 两个线段部分重叠,或收尾相接将看成一个线段) 思路: 在同一一条直线上的两条线段: 他们斜率相等,他们在Y轴或X轴上的投影点相等.然后根据这两个排下序就可以搞出来了. 这题卡精度,要用到eps //#pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <cstring> #incl

【计算几何】【bitset】Gym - 101412G - Let There Be Light

三维空间中有一些(<=2000)气球,一些光源(<=15),给定一个目标点,问你在移除不超过K个气球的前提下,目标点所能接受到的最大光照. 枚举每个光源,预处理其若要照射到光源,需要移走哪些气球,构建成一个bitset. 然后再2^15枚举光源集合,看看要让集合中所有光源照到目标点所要移走的气球是否在K以内,尝试更新答案. 需要注意的一点是,三维叉积叉出来的向量的长度的绝对值,就是原来两个向量所张成的平行四边形面积的大小. #include<cstdio> #include<

【计算几何】【凸包】Gym - 101164H - Pub crawl

平面上n个点,点之间沿直线走,规划一条路线,每次只能往左半平面的点走,走过最多的点. 显然所有的点都能走过. n^2的暴力显然是每次找左边与其所形成夹角最小的点,但这样过不了(卡常数?). 或者每轮不断求凸包.有个非常巧妙的地方是将每一轮输出后剩下的最后一个点加到下一轮的点里面一起求凸包,这样只要按逆时针输出每一轮,就能满足. #include<cstdio> #include<cmath> #include<algorithm> using namespace std

【计算几何】【凸包】【极角排序】【二分】Gym - 101128J - Saint John Festival

平面上n个红点,m个黑点,问你多少个黑点至少在一个红三角形内. 对红点求凸包后,转化为询问有多少个黑点在凸包内. 点在凸多边形内部判定,选定一个凸包上的点作原点,对凸包三角剖分,将其他的点极角排序之后,使用二分法就可以判定点在哪个剖分出来的三角形的夹角内,然后用叉积即可判定其在凸包内还是外,O(logn): http://www.cnblogs.com/dream-wind/archive/2012/05/23/2514694.html #include<cstdio> #include<