土地划分[fzu1015]

题面描述

传送门

思路

线段是否有交点,

之后答案为交点数+原有点数。

注意,这里由于相连线段之间有交点,所以与跨立实验的有些不同。

AC code

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
const int N=3e3+10;
struct node{double x,y;}p[N];
double mul(node p1,node p2,node p0)
{
	double x1=p1.x-p0.x,y1=p1.y-p0.y;
	double x2=p2.x-p0.x,y2=p2.y-p0.y;
	return x1*y2-x2*y1;
}
struct segment
{
	node p1,p2;segment(){}
	segment(node p1,node p2):p1(p1),p2(p2){}
}sg[N];
/*
node jd(segment sg1,segment sg2)
{
	node p1=sg1.p1,p2=sg1.p2,p3=sg2.p1,p4=sg2.p2,p;
	double t1=mul(p1,p4,p3),t2=mul(p2,p4,p3);
	p.x=(t1*p2.x-t2*p1.x)/(t1-t2);
	p.y=(t1*p2.y-t2*p1.y)/(t1-t2);return p;
}
*/
double mymin(double x,double y){return x<y?x:y;}
double mymax(double x,double y){return x>y?x:y;}
bool jg(node p1,node p2,node p3)
{return mymin(p1.x,p2.x)<=p3.x&&mymax(p1.x,p2.x)>=p3.x&&mymin(p1.y,p2.y)<=p3.y&&mymax(p1.y,p2.y)>=p3.y;}
bool pd(segment sg1,segment sg2)
{
	node p1=sg1.p1,p2=sg1.p2,p3=sg2.p1,p4=sg2.p2;
	if(mul(p3,p2,p1)*mul(p2,p4,p1)>0&&mul(p1,p4,p3)*mul(p4,p2,p3)>0)return true;
	/*if(mul(p3,p2,p1)==0&&jg(p1,p2,p3))return true;
    if(mul(p2,p4,p1)==0&&jg(p1,p2,p4))return true;
    if(mul(p1,p4,p3)==0&&jg(p3,p4,p1))return true;
    if(mul(p4,p2,p3)==0&&jg(p3,p4,p2))return true;*/
    return false;
}
int main()
{
	int a,b,n;
	while(scanf("%d%d",&a,&b)&&a&&b)
	{
		scanf("%d",&n);
		scanf("%lf%lf",&p[1].x,&p[1].y);
		for(int i=2;i<=n+1;i++)
		{
			scanf("%lf%lf",&p[i].x,&p[i].y);
			sg[i-1]=segment(p[i-1],p[i]);
		}
		int ans=0;
		for(int i=1;i<=n;i++)
			for(int j=i+1;j<=n;j++)
				if(pd(sg[i],sg[j]))ans++;
		ans+=n+1;printf("%d\n",ans);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值