【POJ_3348】Cows

119 篇文章 0 订阅

在这里插入图片描述

思路:

凸包板题

c o d e code code

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long n, top, s[1000010];
double ans;
struct node
{
	double x, y;
}p[1000010];
double cj(double x, double y, double x1, double y1, double x2, double y2)
{
	return (x1-x)*(y2-y)-(x2-x)*(y1-y);
}
double dis(double x, double y, double x1, double y1)
{
	return sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
}
bool cmp(node x, node y)
{
	double o=cj(p[1].x, p[1].y, x.x, x.y, y.x, y.y);
	if(o>0)
	   return 1;
	if(o==0&&dis(x.x, x.y, p[1].x, p[1].y)<dis(y.x, y.y, p[1].x, p[1].y))
	   return 1;
	return 0;
}
double js(double x, double y, double x1, double y1)
{
	return x*y1-y*x1;
}
int main()
{
	scanf("%lld", &n);
	for(long long i=1; i<=n; i++)
	{
	 	scanf("%lf%lf", &p[i].x, &p[i].y);
	 	if(i!=1&&p[i].y<p[1].y)
	 	{
	 	    swap(p[i].x, p[1].x);
	 	    swap(p[i].y, p[1].y);
		}
		else if(i!=1&&p[i].y==p[1].y&&p[i].x<p[1].x)
		{
	 	   	swap(p[i].x, p[1].x);
	 	  	swap(p[i].y, p[1].y);
		}
	 }
	sort(p+2, p+1+n, cmp);
	s[1]=1, top=1;
	for(long long i=2; i<=n; i++)
	{
	 	while(top>1&&cj(p[s[top-1]].x, p[s[top-1]].y, p[s[top]].x, p[s[top]].y, p[i].x, p[i].y)<=0)
	 	   top--;
	 	s[++top]=i;
	}
	s[top+1]=1;
	for(long long i=1; i<=top; i++)
	    ans+=js(p[s[i]].x, p[s[i]].y, p[s[i+1]].x, p[s[i+1]].y);
	int ans1=ans/100;
	printf("%d", ans1);
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值