1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<iostream>
5 #include<algorithm>
6 #include<cmath>
7 using namespace std;
8 #define Maxn 110
9 const double eps=1e-10;
10 const double INF=1e12;
11
12 double a[Maxn][Maxn],b[Maxn][Maxn];
13
14 int visx[Maxn],visy[Maxn],match[Maxn];
15 double slack[Maxn],lx[Maxn],ly[Maxn];
16 int n;
17
18 bool ffind(double mid,int x,int nt)
19 {
20 visx[x]=nt;
21 for(int y=1;y<=n;y++) if(visy[y]!=nt)
22 {
23 if(fabs(lx[x]+ly[y]-(a[x][y]-mid*b[x][y]))<eps)
24 {
25 visy[y]=nt;
26 if(!match[y]||ffind(mid,match[y],nt))
27 {
28 match[y]=x;
29 return 1;
30 }
31 }
32 else slack[y]=min(slack[y],lx[x]+ly[y]-(a[x][y]-mid*b[x][y]));
33 }
34 return 0;
35 }
36
37 bool check(double mid)
38 {
39 for(int i=1;i<=n;i++) match[i]=0;
40 for(int i=1;i<=n;i++)
41 {
42 visx[i]=visy[i]=0;
43 lx[i]=-INF;ly[i]=0;
44 for(int j=1;j<=n;j++) lx[i]=max(lx[i],a[i][j]-mid*b[i][j]);
45 }int nt=0;
46 for(int i=1;i<=n;i++)
47 {
48 for(int j=1;j<=n;j++) slack[j]=INF;
49 while(1)
50 {
51 nt++;
52 if(ffind(mid,i,nt)) break;
53 double delta=INF;
54 for(int j=1;j<=n;j++) if(visy[j]!=nt) delta=min(delta,slack[j]);
55 for(int j=1;j<=n;j++)
56 {
57 if(visx[j]==nt) lx[j]-=delta;
58 if(visy[j]==nt) ly[j]+=delta;
59 else if(fabs(INF-slack[j])<eps) slack[j]-=delta;
60 }
61 }
62 }
63 double ans=0;
64 for(int i=1;i<=n;i++) ans+=lx[i]+ly[i];
65 return ans>=0;
66 }
67
68 int main()
69 {
70 double l=0,r=0;
71 scanf("%d",&n);
72 for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%lf",&a[i][j]),r+=a[i][j];
73 for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%lf",&b[i][j]);
74 while(r-l>eps)
75 {
76 double mid=(l+r)/2;
77 if(check(mid)) l=mid;
78 else r=mid;
79 }
80 printf("%.6lf\n",l);
81 return 0;
82 }