(计算几何+二分+网络流)P4048 [JSOI2010]冷冻波

P4048 [JSOI2010]冷冻波

思路:

首先我们可以假设如果有 a n s ans ans分钟的话,巫妖可以攻击 ⌊ a n s t ⌋ + 1 \lfloor\cfrac{ans}{t}\rfloor+1 tans+1次,因为在第 0 0 0秒就可以开始攻击。
很显然的一个建图就是:
S S S向每个巫妖建边,权值为 ⌊ a n s t ⌋ + 1 \lfloor\cfrac{ans}{t}\rfloor+1 tans+1
每个巫妖向自己能过攻击到的精灵建边,权值为 1 1 1
每个精灵向 T T T建边,权值为 1 1 1
然后判断最大流是不是等于 m m m,如果等于 m m m,就表示在这个时间内可以消灭这些精灵。对于 a n s ans ans,可以二分答案进行判断。
如何判断巫妖能否攻击到小精灵呢?
如果巫妖到小精灵的距离大于他的攻击半径,那么显然不行。
对于树的遮挡,先计算树的圆心 O O O到巫妖(看作点 A A A)和小精灵(看作点 B B B)组成的线段 A B AB AB的距离 O H OH OH。存在两种情况,一种是 O H OH OH在线段 A B AB AB上,一种是 O H OH OH在线段 A B AB AB外,可以通过计算 A H + B H AH+BH AH+BH是否等于 A B AB AB来判断。如果 O H OH OH A B AB AB上,那么 O O O A B AB AB的最短距离就为 O H OH OH,否则为 min ⁡ { O A , O B } \min \{OA,OB\} min{OA,OB}然后判断最短距离是否大于半径即可。

代码:

#include<bits/stdc++.h>
#define pii pair<int,int>
#define int long long
#define pb push_back
#define cl(x,y) memset(x,y,sizeof(x))
#define ct cerr<<"Time elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
const int N=1e6+210;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const int minn=0xc0c0c0c0;
const double eps=1e-6;
using namespace std;
int sgn(double x)
{
    if(fabs(x) < eps)return 0;
    if(x < 0) return -1;
    else return 1;
}
struct point
{
    double x,y;
    point(){}
    point(double xx,double yy){x=xx;y=yy;}
    point operator +(point b){return point(x+b.x,y+b.y);}
    point operator -(point b){return point(x-b.x,y-b.y);}
    double operator ^(point b){return x*b.y-y*b.x;}//叉乘 
    double operator *(point b){return x*b.x+y*b.y;}//点乘 
    point operator *(double b){return point(x*b,y*b);}//数乘  
    int operator ==(point b){return (sgn(x-b.x)==0 && sgn(y-b.y)==0);}
	double gettan(){return atan2(y,x);}//角度 
	point spin(double a){return point(x*cos(a)-y*sin(a),y*cos(a)+x*sin(a));}//逆时针旋转a弧度 
    void read(){scanf("%lf%lf",&x,&y);}
}b[N];
struct line
{
    point s,e,l;
    line(){}
    line(point ss,point ee){s = ss;e = ee;l=e-s;}
    void read(){s.read(),e.read();l=e-s;}
    double gettan(){return atan2(e.y-s.y,e.x-s.x);}
};
struct circle
{
	point o;
	double r;
	circle(){}
	circle(point oo,double rr){o=oo;r=rr;}
	point count(double a){return point(o.x + cos(a) * r, o.y + sin(a) * r);}
}c[N];
struct wy
{
	point p;
	double r,t;
}a[N];
double dis(point a)
{
	return sqrt(a*a);
}
double dis_pl(point p,line l)
{
	point v=p-l.s;
	double ans=(v^l.l)/sqrt(l.l*l.l);
	return fabs(ans);
} 
struct edge
{
	int u,v,w;
}maze[N<<1];
int len,head[N]={0};
int dep[N];//深度 
void add(int u,int v,int w)
{
	maze[++len]={head[u],v,w};
	head[u]=len;
}
void inc(int u,int v,int w)
{
	add(u,v,w);
	add(v,u,0);
} 
int dfs(int u,int f,int t)
{
	int ans=0,i;
	if(u==t)
		return f;
	for(i=head[u];i && f;i=maze[i].u)
	{
		int v=maze[i].v,w=maze[i].w;
		if(dep[v]==dep[u]+1 && w)//符合深度关系且能流 
		{
			int sum=dfs(v,min(f,w),t);
			maze[i].w-=sum;
			maze[i^1].w+=sum;
			f-=sum;
			ans+=sum;
		}	
	}
	if(!ans)
		dep[u]=-2;
	return ans;
}
int bfs(int s,int t)
{
	queue<int> q;
	cl(dep,0);
	dep[s]=1;//源点深度为1
	q.push(s);
	while(!q.empty())
	{
		int u=q.front(),i;
		q.pop();
		for(i=head[u];i;i=maze[i].u)
		{
			int v=maze[i].v,w=maze[i].w;
			if(w && !dep[v])//有深度且能流 
			{
				dep[v]=dep[u]+1;
				q.push(v); 
			}
		}
	}
	return dep[t];
}
int dinic(int s,int t)
{
	int ans=0;
	while(bfs(s,t))
		ans+=dfs(s,inf,t);
	return ans;
}
vector<int> d[N];
int n,m,k;
void init()
{
	int i,j,l;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(sgn(dis(a[i].p-b[j])-a[i].r)>0)
				continue;
			int f=1;
			for(l=1;l<=k;l++)
			{
				double oh=dis_pl(c[l].o,line{a[i].p,b[j]});
				double oa=dis(c[l].o-a[i].p);
				double ob=dis(c[l].o-b[j]);
				double ju;
				if(sgn(sqrt(oa*oa-oh*oh)+sqrt(ob*ob-oh*oh)-dis(a[i].p-b[j]))>0)
					ju=min(oa,ob);
				else
					ju=oh;
				if(sgn(ju-c[l].r)<=0)
				{
					f=0;
					break;
				}
			}				
			if(f)
				d[i].pb(j);
		}
	}
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int i,j;
	cin>>n>>m>>k;
	int s=0,t=n+m+1;
	for(i=1;i<=n;i++)
		cin>>a[i].p.x>>a[i].p.y>>a[i].r>>a[i].t;
	for(i=1;i<=m;i++)
		cin>>b[i].x>>b[i].y;
	for(i=1;i<=k;i++)
		cin>>c[i].o.x>>c[i].o.y>>c[i].r;
	init();
	int l=0,r=1e9,ans=-1;
	while(l<=r)
	{
		int mid=(l+r)/2;
		len=1;
		for(i=0;i<=n+m+1;i++)
			head[i]=0;
		for(i=1;i<=n;i++)
			inc(s,i,1+mid/a[i].t);
		for(i=1;i<=m;i++)
			inc(i+n,t,1);
		for(i=1;i<=n;i++)
			for(j=0;j<d[i].size();j++)
				inc(i,d[i][j]+n,1);
		if(dinic(s,t)==m)
		{
			r=mid-1;
			ans=mid;
		}
		else
			l=mid+1;
	}
	cout<<ans<<endl;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值