poj.3384Cows(计算几何)(凸包)

Posted SSL_LKJ

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了poj.3384Cows(计算几何)(凸包)相关的知识,希望对你有一定的参考价值。

Cows

题目传送门
Description

Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are forced to save money on buying fence posts by using trees as fence posts wherever possible. Given the locations of some trees, you are to help farmers try to create the largest pasture that is possible. Not all the trees will need to be used.

However, because you will oversee the construction of the pasture yourself, all the farmers want to know is how many cows they can put in the pasture. It is well known that a cow needs at least 50 square metres of pasture to survive.

Input

The first line of input contains a single integer, n (1 ≤ n ≤ 10000), containing the number of trees that grow on the available land. The next n lines contain the integer coordinates of each tree given as two integers x and y separated by one space (where -1000 ≤ x, y ≤ 1000). The integer coordinates correlate exactly to distance in metres (e.g., the distance between coordinate (10; 11) and (11; 11) is one metre).

Output

You are to output a single integer value, the number of cows that can survive on the largest field you can construct using the available trees.

输入样例

4
0 0
0 101
75 0
75 101

输出样例

151

解题思路

这题与P2742 [USACO5.1]圈奶牛Fencing the Cows /【模板】二维凸包(计算几何)(凸包)类似
凸包模板

AC代码

#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int n,tot;
long long ans;
struct node

	int x,y;
a[10005],q[10005];
int cj(node x1,node x2,node x3,node x4)

	return (x2.x-x1.x)*(x4.y-x3.y)-(x2.y-x1.y)*(x4.x-x3.x);

int juli(node x,node y)

	return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));

bool cmp(node x,node y)

	int o=cj(a[1],x,a[1],y);
	if(o>0)return 1;
	if(!o&&juli(a[0],x)<juli(a[0],y))return 1;
	return 0;

int main()

	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	
		scanf("%d%d",&a[i].x,&a[i].y);
		if(a[i].y<a[1].y||(a[i].y==a[1].y&&a[i].x<a[1].x))
		
			swap(a[i].x,a[1].x);
			swap(a[i].y,a[1].y);
		
	
	sort(a+2,a+n+1,cmp);
	q[++tot]=a[1];
	for(int i=2;i<=n;i++)
	
		while(tot>1&&cj(q[tot-1],q[tot],q[tot],a[i])<=0)tot--;
		q[++tot]=a[i];
	
	q[tot+1]=a[1];
	for(int i=1;i<=tot;i++)ans+=q[i].x*q[i+1].y-q[i].y*q[i+1].x;
	printf("%lld",ans/100);
	return 0;

谢谢

以上是关于poj.3384Cows(计算几何)(凸包)的主要内容,如果未能解决你的问题,请参考以下文章

poj.3384Cows(计算几何)(凸包)

P2742 [USACO5.1]圈奶牛Fencing the Cows /模板二维凸包(计算几何)(凸包)

P2742 [USACO5.1]圈奶牛Fencing the Cows /模板二维凸包(计算几何)(凸包)

P2742 [USACO5.1]圈奶牛Fencing the Cows /模板二维凸包(计算几何)(凸包)

Cows 计算几何 求凸包 求多边形面积

P2742 [USACO5.1]圈奶牛Fencing the Cows /模板二维凸包