Description
The X Corps and the Y Corps are fighting fiercely in 3333 on a planet in the Milky Way. At some stage of the fight, the Y Corps dispatched n massive robots to attack the X Regiment's position, of which the armor value of the first giant robot was AI. When the armor of a giant robot is reduced to 0 or less, the giant robot is destroyed. The X Legion has m laser weapons, of which the first laser weapon can cut the armor value of a giant robot bi per second. The attack of laser weapons is continuous. This laser weapon is so strange that a laser weapon can only attack certain enemies. The Y Corps saw their giant robots wiped out by one of the X legions, and they desperately needed more orders. For this purpose, the Y Corps needs to know how long it will take at least for the X Legion to destroy all the giant robots of the Y Corps. But they don't count the problem, so they turn to you for help. Input
First row, two integers, N, M.
Second row, n integers, A1, A2 ... An.
Third line, M integer, B1, B2 ... Bm.
The next m rows, n integers per row, these integers are either 0 or 1. The number of J integers in line I of this section is 0, which means that the first laser weapon is not allowed to attack the J Giant Robot, and 1 indicates that the first laser weapon can attack the first J giant Robot. Output
One line, a real number, represents the minimum amount of time that the X Legion will need to destroy all the giant robots in the Y Corps. The output result and the absolute error of the standard answer are not more than 10-3, which is considered correct. Sample Input
2 2
3
4 6 0
1 1
1
Sample Output
1.300000
HINT
"Sample Illustration 1"
After the battle began in the first 0.5 seconds, laser weapons 1 attack 2nd giant robots, laser weapons 2 attack the giant robot 1th. The 1th giant robot was completely destroyed, and the 2nd mega-robot still had 8 armor remaining;
For the next 0.8 seconds, laser weapons 1 and 2 attack the giant robot 2nd at the same time. The 2nd giant robot was completely destroyed.
For all the data, 1<=n, m<=50,1<=ai<=105,1<=bi<=1000, enter data to ensure that the X Legion will destroy all the giant droid Source of the Y Corps.
Round 1 Thanks yts1999 upload
Brush the water question edify sentiment ...
Note the upper bound of the two-point ... 1 billion will t to die ...
Deep don't turn into a bool again ...
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <
Cmath> #include <queue> using namespace std;
typedef long Long LL;
const int SZ = 1010;
Const double INF = 5e6;
Const double EPS = 1e-4;
int head[sz],nxt[10000],tot = 1,n,m;
struct edge{int t;
Double D;
}L[10000];
void build (int f,int t,double d) {l[++ tot].t = t;
L[TOT].D = D;
Nxt[tot] = head[f];
HEAD[F] = tot;
} void Insert (int f,int t,double D) {build (F,t,d), build (t,f,0.0);
int Deep[sz];
Queue<int> Q;
BOOL BFS (int s,int e) {memset (deep,0,sizeof (deep));
while (Q.size ()) Q.pop ();
Deep[s] = 1;
Q.push (s);
while (Q.size ()) {int u = q.front (); Q.pop ();
for (int i = Head[u];i;i = Nxt[i]) {int v = l[i].t;
if (l[i].d &&!deep[v]) {Deep[v] = Deep[u] + 1;
if (v = = e) return true;
Q.push (v); }} return false;
Double dfs (int u,double flow,int e) {if (Flow < EPS | | u = e) return flow;
Double rest = flow;
for (int i = Head[u];i;i = Nxt[i]) {int v = l[i].t;
if (l[i].d && deep[v] = = Deep[u] + 1) {Double F = DFS (V,min (REST,L[I].D), E);
if (F > EPs) {l[i].d = f;
l[i ^ 1].d = f;
rest = f;
if (rest < EPS) break;
else deep[v] = 0;
} return flow-rest;
Double dinic (int s,int e) {double ans = 0;
while (BFS (s,e)) ans + = DFS (s,inf,e);
return ans;
} void Init () {memset head,0,sizeof (head);
tot = 1;
int A[sz],b[sz];
BOOL maps[233][233];
BOOL Check (double mid) {init ();
int s = n + M + 1;
int e = n + M + 2;
for (int i = 1;i <= m;i + +) Insert (s,i + n,mid * b[i));
Double sum = 0; for (int i= 1;i <= n;i + +) Insert (I,e,a[i]), sum + = a[i]; for (int i = 1;i <= m;i + +) for (int j = 1;j <= N;j + +) if (maps[i][j)) Insert (i +
N,j,mid * B[i]);
Double ans = dinic (s,e);
return Fabs (Ans-sum) < EPS;
Double Div () {double L = 0,r = INF;
while (Fabs (r-l) > EPS) {double mid = (L + r)/2;
if (check (mid)) R = Mid;
else L = mid;
} return R;
int main () {scanf ("%d%d", &n,&m);
for (int i = 1;i <= n;i + +) scanf ("%d", &a[i]);
for (int i = 1;i <= m;i + +) scanf ("%d", &b[i]);
for (int i = 1;i <= m;i + +) for (int j = 1;j <= n;j + +) scanf ("%d", &maps[i][j]);
printf ("%.6lf\n", div ());
return 0;
}