[二分答案+对偶图 || 三角剖分] BZOJ 3007 拯救小云公主 && BZOJ 4219 跑得比谁都快

3007是小数据 可二分答案:http://blog.csdn.net/popoqqq/article/details/44224815

4219是大数据 三角剖分 平面欧几里德最小生成树:http://trinkle.is-programmer.com/2015/7/13/bzoj-3007.102710.html


3007的代码 4219不会打... 先挖个坑


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#define cl(x) memset(x,0,sizeof(x))
#define V G[p].v
using namespace std;

inline char nc()
{
	static char buf[100000],*p1=buf,*p2=buf;
	if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
	return *p1++;
}

inline void read(int &x){
	char c=nc(),b=1;
	for (;!(c>='0' && c<='9');c=nc()) if (c=='-') c=-1;
	for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

const int N=3005;

struct Point{
	int x,y;
	void read(){
		::read(x); ::read(y);
	}
	friend double Dist(Point A,Point B){
		return sqrt((double)(A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
	}
}P[N],pos;

struct edge{
	int u,v;
	int next;
};

edge G[N*N];
int head[N],inum;

inline void add(int u,int v,int p){
	G[p].u=u; G[p].v=v; G[p].next=head[u]; head[u]=p;
}

int n,S,T;
double dis[N][N];

int Q[N],l,r;
int ins[N];

inline bool bfs(){
	l=r=-1;
	Q[++r]=S; ins[S]=1; cl(ins);
	while (l<r){
		int u=Q[++l];
		for (int p=head[u];p;p=G[p].next)
			if (!ins[V])
			{
				Q[++r]=V; ins[V]=1;
				if (V==T) return 1;
			}
	}
	return 0;
}

inline bool Check(double mid){
	cl(head); inum=0;
	for (int i=1;i<=n;i++)
	{
		if (P[i].x-1<mid || pos.y-P[i].y<mid)
			add(S,i,++inum);
		if (pos.x-P[i].x<mid || P[i].y-1<mid)
			add(i,T,++inum);
	}
	for(int i=1;i<=n;i++)  
		for (int j=1;j<i;j++)
			if (dis[i][j]<2*mid)
				add(j,i,++inum),add(i,j,++inum);  
	return !bfs();	
}

inline void Bin()
{
	double L=0,R=min(pos.x-1,pos.y-1),MID;  
	while(R-L>1e-4) 
		if(Check(MID=(L+R)/2))  
			L=MID;
		else  
			R=MID;  
	printf("%.2lf\n",(L+R)/2);  
}

int main()
{
	freopen("t.in","r",stdin);
	freopen("t.out","w",stdout);
	read(n); pos.read();
	S=n+1; T=n+2;
	for (int i=1;i<=n;i++) P[i].read();
	for (int i=1;i<=n;i++)
		for (int j=1;j<i;j++)
			dis[j][i]=dis[i][j]=Dist(P[i],P[j]);
	Bin();
	return 0;
}


你可能感兴趣的:([二分答案+对偶图 || 三角剖分] BZOJ 3007 拯救小云公主 && BZOJ 4219 跑得比谁都快)