【BZOJ 2618】[Cqoi2006]凸多边形 半平面交

236 篇文章 0 订阅
8 篇文章 0 订阅

转成半平面交就好了。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define eps 1e-7
#define maxn 100021 
using namespace std;
int n,tot,cnt;
struct P{
	double x,y;
	P(double a=0,double b=0):x(a),y(b){}
}p[maxn],a[maxn];
typedef P vec;
vec operator-(P a,P b){return vec(a.x-b.x,a.y-b.y);}
double operator*(vec a,vec b){return a.x*b.y-a.y*b.x;}
P operator+(P a,P b){return P(a.x+b.x,a.y+b.y);}
vec operator*(vec a,double b){return vec(a.x*b,a.y*b);}
struct Line{
	P fr,sc;double slop;
	void init(P x,P y){
		fr=x,sc=y;
		slop=atan2(sc.y-fr.y,sc.x-fr.x);
	}
	bool operator<(const Line& b)const {
		if(slop!=b.slop)return slop<b.slop;
		return (sc-fr)*(b.sc-fr)<0;
	}
}l[maxn],q[maxn*2];


P insert(Line xx,Line yy){
	P a=xx.fr,b=xx.sc,x=yy.fr,y=yy.sc;
	double s1=(b-a)*(y-a),s2=(x-a)*(b-a);
	double t=s2/(s1+s2);
	return x+(y-x)*t;
}
bool cheak(Line a,Line b,Line c){
	P x=insert(a,b);
	return (c.sc-c.fr)*(x-c.fr)<0;
}

void make(){
	int L=1,R=1;q[L]=l[1];q[++R]=l[2];
	for(int i=3;i<=cnt;i++){
		while(L<R&&cheak(q[R-1],q[R],l[i]))R--;
		while(L<R&&cheak(q[L],q[L+1],l[i]))L++;
		q[++R]=l[i];
	}
	while(L<R&&cheak(q[R-1],q[R],q[L]))R--;
	q[R+1]=q[L];
	for(int i=L;i<=R;i++){
		a[++tot]=insert(q[i],q[i+1]);
	}
}

int main(){
	scanf("%d",&n);
	for(int k,i=1;i<=n;i++){
		scanf("%d",&k);
		for(int j=1;j<=k;j++)scanf("%lf%lf",&p[j].x,&p[j].y);
		p[k+1]=p[1];
		for(int j=1;j<=k;j++){
			l[++cnt].init(p[j],p[j+1]);
		}
	}sort(l+1,l+1+cnt);
	for(int i=1;i<=cnt;i++){
		if(l[i].slop!=l[i-1].slop)
			l[++tot]=l[i];
	}cnt=tot;tot=0;
	make();
	if(tot<=2)return puts("0.000"),0;
	double ans=0;a[tot+1]=a[1];
	for(int i=1;i<=tot;i++){
		ans+=a[i]*a[i+1];
	}printf("%.3lf",fabs(ans)/2);
	return 0;
}


根据引用所述,错序列是一个仅由0和1构成的序列,其中没有相邻的1(可以有相邻的0)。特征值定义为x^ay^b,其中x和y分别表示0和1出现的次数。长度为n的错序列可能有多个。问题要计算所有长度为n的错序列特征值的和除以m的余数。 根据引用所述,输入文件包含一个行,该行包含三个整数n、a、b和m。其中,1≤n≤10000000,0≤a、b≤45,m<100000000。 为了解决这个问题,可以使用动态规划和矩阵快速幂优化的方法,具体实现可以参考引用提到的相关算法。算法的思路是通过计算长度为n的错序列的特征值,然后将所有特征值和并对m取余数。 具体步骤如下: 1. 使用动态规划计算长度为n的所有错序列的特征值,将结果保存在一个矩阵中。 2. 使用矩阵快速幂优化,将动态规划的过程进行优化。 3. 对优化后的结果进行和,并对m取余数。 4. 输出结果。 参考引用给出的博客中的代码实现,可以帮助你更好地理解和实现该算法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [BZOJ5298 CQOI2018 错序列 【DP+矩阵快速幂优化】*](https://blog.csdn.net/weixin_30892987/article/details/99470493)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值