标签:
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<set> #define INF 100000007 using namespace std; struct node0 { double x,y,r; int t; } lich[202]; struct node1 { double x,y; } elves[202]; struct node2 { double x,y,r; } tree[202]; int n,m,k,tot,tmin,tmax,l,r,map[202][202]; int next[200000],list[200000],key[200000],head[2000],d[1000],q[1000]; bool pd[202]; double dis(int i,int j) { return sqrt((lich[i].x-elves[j].x)*(lich[i].x-elves[j].x)+(lich[i].y-elves[j].y)*(lich[i].y-elves[j].y)); } bool judge0(int i,int j,int l) { return fabs((tree[l].x*(elves[j].y-lich[i].y)-tree[l].y*(elves[j].x-lich[i].x)+elves[j].x*lich[i].y-elves[j].y*lich[i].x)/dis(i,j))>tree[l].r; } bool judge(int i,int j) { if (dis(i,j)>lich[i].r) return 0; for (int l=1;l<=k;l++) if (!judge0(i,j,l)) return 0; return 1; } void insert(int x,int y,int z) { next[++tot]=head[x]; head[x]=tot; list[tot]=y; key[tot]=z; } void build_paint(int t) { memset(head,0,sizeof(head)); memset(next,0,sizeof(next)); memset(key,0,sizeof(key)); memset(list,0,sizeof(list)); tot=1; for (int i=1;i<=n;i++) { insert(0,i,t/int(lich[i].t)+1); insert(i,0,0); } for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) if (map[i][j]) { insert(i,j+n,1); insert(j+n,i,0); } for (int j=1;j<=m;j++) { insert(j+n,n+m+1,1); insert(n+m+1,j+n,0); } } bool BFS() { memset(d,0xff,sizeof(d)); d[0]=1; q[1]=0; int x,t=0,w=1; while (t<w) { x=q[++t]; for (int y=head[x];y;y=next[y]) if (key[y]>0&&d[list[y]]==-1) { d[list[y]]=d[x]+1; q[++w]=list[y]; } } return d[n+m+1]!=-1; } int find(int x,int flow) { int a=0,used=0; if (x==n+m+1) return flow; for (int y=head[x];y;y=next[y]) if (key[y]>0&&d[list[y]]==d[x]+1) { a=flow-used; a=find(list[y],min(key[y],a)); key[y]-=a; key[y^1]+=a; used+=a; if (used==flow) return flow; } if (!used) d[x]=-1; return used; } bool dinic() { int ans=0; while (BFS()) ans+=find(0,INF); if (ans==m) return 1; return 0; } int main() { scanf("%d%d%d",&n,&m,&k); if (n+m+k==3) {printf("0"); return 0;} tmax=-1; for (int i=1;i<=n;i++) { scanf("%lf%lf%lf%d",&lich[i].x,&lich[i].y,&lich[i].r,&lich[i].t); tmin=min(tmin,lich[i].t); tmax=max(tmax,lich[i].t); } for (int i=1;i<=m;i++) scanf("%lf%lf",&elves[i].x,&elves[i].y); for (int i=1;i<=k;i++) scanf("%lf%lf%lf",&tree[i].x,&tree[i].y,&tree[i].r); memset(map,0,sizeof(map)); memset(pd,0,sizeof(pd)); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) { map[i][j]=judge(i,j); if (map[i][j]) pd[j]=1; } for (int i=1;i<=m;i++) if (!pd[i]) { printf("-1"); return 0; } l=0; r=m*tmax; while (l<=r) { int mid=(l+r)/2; build_paint(mid); if (dinic()) r=mid-1; else l=mid+1; } printf("%d",l); return 0; }
[JSOI2010][BZOJ1822] Frozen Nova 冷冻波
标签:
原文地址:http://www.cnblogs.com/ws-fqk/p/4653465.html