BZOJ_3993_[SDOI2015] Interstellar War _ two points + network flow
Description
In 3333, on a planet in the Milky Way, the X Corps and the Y Corps are fighting fiercely. At a certain stage of the battle, the Y Corps sent a total of N giant robots to attack the X Corps positions, of which the i-th giant robot had an armor value of Ai. When a giant robot's armor value is reduced to 0 or below, the giant robot is destroyed. X Corps has M laser weapons, of which the i-th laser weapon can reduce the armor value of a giant robot Bi every second. The attack of the laser weapon is continuous. This laser weapon is very strange, a laser weapon can only attack some specific enemies. The Y Corps saw their giant robots being wiped out by the X Corps one by one, and they urgently needed more orders. For this purpose, the Y Corps needs to know the minimum time it will take for the X Corps to destroy all the giant robots of the Y Corps. But they don't count the problem, so turn to you for help.
Input
The first line, two integers, N, M.
Output
One line, a real number, represents the minimum time it would take for the X Corps to destroy all the giant robots of the Y Corps. The absolute error between the output result and the standard answer is no more than 10-3, which is regarded as correct.
Sample Input
3 10
4 6
0 1
1 1
Sample Output
HINT
【Example Description 1】
#include <stdio.h> #include <string.h> #include <algorithm> #include <stdlib.h> using namespace std; typedef double f2; #define N 150 #define M 300050 #define S (n+m+1) #define T (n+m+2) #define inf 10000000 f2 flow[M]; int head[N],to[M],nxt[M],cnt,n,m,a[N],b[N]; int dep[N],Q[N],l,r,sum,map[N][N]; f2 fabs(f2 x){return x>0?x:-x;} inline void add(int u,int v,f2 w) { to[++cnt]=v; nxt[cnt]=head[u]; head[u]=cnt; flow[cnt]=w; to[++cnt]=u; nxt[cnt]=head[v]; head[v]=cnt; flow[cnt]=0; } bool bfs() { memset(dep,0,sizeof(dep)); dep[S]=1;int i;l=r=0;Q[r++]=S; while(l<r) { int x=Q[l++]; for(i=head[x];i;i=nxt[i]) if(!dep[to[i]]&&flow[i]) { dep[to[i]]=dep[x]+1; if(to[i]==T) return 1; Q[r++]=to[i]; } } return 0; } f2 dfs(int x,f2 mf) { if(x==T) return mf; int i; f2 nf=0; for(i=head[x];i;i=nxt[i]) { if(dep[to[i]]==dep[x]+1&&flow[i]) { f2 tmp=dfs(to[i],min(mf-nf,flow[i])); nf+=tmp; flow[i]-=tmp; flow[i^1]+=tmp; if(nf==mf) break; } } dep[x]=0; return nf; } bool check(f2 x) { memset(head,0,sizeof(head)); cnt=1; int i,j; for(i=1;i<=n;i++) add(i,T,a[i]); for(i=1;i<=m;i++) add(S,i+n,b[i]*x); for(i=1;i<=m;i++) { for(j=1;j<=n;j++) if(map[i][j]) { add(i+n,j,inf); } } f2 years=0,f; while(bfs()) while(1) { f2 f=dfs(S,inf); if(fabs(f)<1e-6) break; ans+=f; } return fabs(ans-sum)<1e-6; } int main() { scanf("%d%d",&n,&m); int i,j; for(i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i]; for(i=1;i<=m;i++) scanf("%d",&b[i]); for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { scanf("%d",&map[i][j]); } } f2 L=0,R=1e5; for(i=1;i<=70;i++) { f2 mid=(L+R)/2; if(check(mid)) R=mid; else L=mid; } printf("%.4lf\n",L); }