标签:mem its scanf reset bool str bitset eset nod
标程:
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=405; 4 const int inf=0x3f3f3f3f; 5 typedef long long ll; 6 int cnt=1,n,m,ans,Rx,xa[N],xb[N],yb[N],ya[N],head[N],Head[N],tot,S,T,dis[N]; 7 ll Ans; 8 queue<int> q; 9 bitset<N> f[N]; 10 struct node{int to,next,f;}num[N*N]; 11 struct Node{int d,x,y;Node(){} Node(int A,int B,int C){d=A;x=B;y=C;}}p[N*N]; 12 void add(int x,int y,int w) 13 { 14 num[++cnt].to=y;num[cnt].next=head[x];num[cnt].f=w;head[x]=cnt; 15 num[++cnt].to=x;num[cnt].next=head[y];num[cnt].f=0;head[y]=cnt; 16 if (!f[x][y]) 17 for (int i=1;i<=T;i++) if (f[i][x]&&!f[i][y]) f[i]|=f[y]; 18 } 19 void init() 20 { 21 for (int i=1;i<=T;i++) f[i].reset(),f[i][i]=1; 22 for (int i=1;i<=T;i++) 23 for (int j=head[i];j;j=num[j].next) 24 if (num[j].f) f[i][num[j].to]=1; 25 for (int i=1;i<=T;i++) 26 for (int j=1;j<=T;j++) if (f[i][j]) f[i]|=f[j]; 27 } 28 int bfs() 29 { 30 memset(dis,0,sizeof(dis));dis[S]=1;q.push(S); 31 while (!q.empty()) 32 { 33 int now=q.front();q.pop(); 34 for (int i=head[now];i;i=num[i].next) 35 if (num[i].f&&!dis[num[i].to]) dis[num[i].to]=dis[now]+1,q.push(num[i].to); 36 } 37 return dis[T]; 38 } 39 int dfs(int x,int Min) 40 { 41 int tmp=Min; 42 if (x==T||!Min) return Min; 43 for (int &i=Head[x];i&&tmp;i=num[i].next) 44 if (dis[num[i].to]==dis[x]+1) 45 { 46 int t=dfs(num[i].to,min(tmp,num[i].f)); 47 num[i].f-=t;num[i^1].f+=t;tmp-=t; 48 } 49 return Min-tmp; 50 } 51 int dinic() 52 { 53 if (!f[S][T]) return 0; 54 int res=0,tmp; 55 while (bfs()) 56 { 57 memcpy(Head,head,sizeof(head)); 58 while (tmp=dfs(S,inf)) res+=tmp; 59 } 60 init(); 61 return res; 62 } 63 int get_dis(int i,int j){return (xa[i]-xb[j])*(xa[i]-xb[j])+(ya[i]-yb[j])*(ya[i]-yb[j]);} 64 bool cmp(const Node &A,const Node &B){return A.d<B.d;} 65 int main() 66 { 67 scanf("%d%d%d",&n,&m,&Rx);S=n+m+1;T=S+1; 68 for (int i=1;i<=T;i++) f[i][i]=1; 69 for (int i=1;i<=n;i++) add(S,i,1); 70 for (int i=1;i<=m;i++) add(i+n,T,1); 71 for (int i=1;i<=n;i++) scanf("%d",&xa[i]); 72 for (int i=1;i<=n;i++) scanf("%d",&ya[i]); 73 for (int i=1;i<=m;i++) scanf("%d",&xb[i]); 74 for (int i=1;i<=m;i++) scanf("%d",&yb[i]); 75 for (int i=1;i<=n;i++) 76 for (int j=1;j<=m;j++) p[++tot]=Node(get_dis(i,j),i,j); 77 p[++tot]=Node(Rx*Rx*4,0,0); 78 sort(p+1,p+tot+1,cmp); 79 for (int i=0;i<=tot&&p[i].d<=Rx*Rx*4;i++)//从0开始,有可能 80 { 81 add(p[i].x,p[i].y+n,1); 82 if (p[i].d!=p[i+1].d) ans+=dinic(),Ans=max(Ans,min((ll)max(p[i+1].d,p[i].d),Rx*Rx*4ll)*(n+m-ans));//注意取后一个半径进行运算,注意边界! 83 } 84 printf("%.4lf\n",(double)Ans*M_PI*0.25); 85 return 0; 86 }
标签:mem its scanf reset bool str bitset eset nod
原文地址:https://www.cnblogs.com/Scx117/p/9065852.html