
1 <= W <= 50,000 1 <= L <= 50,000 1 <= N <= 250
考虑题目的限制被挡住就说明首尾相接的圆堵住了,如下图:![]()
就跟NOIP2017年那个题一样,删去最少的圆使上下两边界不连通
代码如下:
//MT_LI #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<ctime> #include<map> #include<bitset> #include<set> #define ll long long #define mp(x,y) make_pair(x,y) #define pll pair<long long,long long> #define pii pair<int,int> using namespace std; inline ll read() { ll f=1,x=0;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } int stack[20]; inline void write(int x) { if(x<0){putchar(‘-‘);x=-x;} if(!x){putchar(‘0‘);return;} int top=0; while(x)stack[++top]=x%10,x/=10; while(top)putchar(stack[top--]+‘0‘); } inline void pr1(int x){write(x);putchar(‘ ‘);} inline void pr2(int x){write(x);putchar(‘\n‘);} struct dicnic{ int x,y,c,next,other; }a[2100000];int len,last[1100]; void ins(int x,int y,int c) { a[++len]=(dicnic){x,y,c,last[x],len+1},last[x]=len; a[++len]=(dicnic){y,x,0,last[y],len-1},last[y]=len; } int h[1100],head,tail; int st,ed,list[1100]; bool bt_h() { memset(h,0,sizeof(h));h[st]=1; head=1,tail=2;list[1]=st; while(head!=tail) { int x=list[head]; for(int k=last[x];k;k=a[k].next) { int y=a[k].y; if(h[y]==0&&a[k].c) { h[y]=h[x]+1; list[tail++]=y; } } head++; } if(h[ed])return true; return false; } int findflow(int x,int f) { if(x==ed)return f; int s=0,t; for(int k=last[x];k;k=a[k].next) { int y=a[k].y; if(h[y]==h[x]+1&&a[k].c&&s<f) { s+=(t=findflow(y,min(a[k].c,f-s))); a[k].c-=t;a[a[k].other].c+=t; } } if(s==0)h[x]=0; return s; } int L,W,n; struct node{ ll x,y; }e[260]; ll S(ll x){return x*x;} int main() { L=read(),W=read(),n=read();st=0,ed=2*n+1; memset(last,0,sizeof(last));len=0; for(int i=1;i<=n;i++) { e[i].x=read(),e[i].y=read(); if(e[i].y<=100)ins(st,i,1); if(e[i].y>=W-100)ins(i+n,ed,1); ins(i,i+n,1); } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j) if(S(e[i].x-e[j].x)+S(e[i].y-e[j].y)<=40000) ins(i+n,j,1); int ans=0; while(bt_h())ans+=findflow(st,1<<30); printf("%d\n",ans); return 0; }
BZOJ1340: [Baltic2007]Escape逃跑问题
原文:https://www.cnblogs.com/MT-LI/p/10808415.html