Bzoj 3993: [Sdoi2015] Star Wars __ Network streaming

Source: Internet
Author: User
Tags first row
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 10
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 droids of the Y Corps.

Source

Round 1 Thanks yts1999 upload


Second time, then build two rows of line point run network flow. Source left a row. Traffic is the attack output. A row of links to the right. The flow is armor value. Intermediate interconnection. Unlimited Flow

"Remember to get EPS, be careful not to be card precision"

#include <cstdio> #include <string> #include <cstring> #include <algorithm> using namespace std;
     struct line {int s,t;
     Double F;
int next;
}A[100001];
int head[1001];
int edge;
Double eps=10e-5;
     inline void Add (int s,int t,double f) {a[edge].next=head[s];
     Head[s]=edge;
     A[edge].s=s;
     a[edge].t=t;
A[edge].f=f;
Double aa[1001],bb[1001];
int dep[1001],q[100001];
int map[1001][1001];
int p;
     inline bool BFs (int d) {memset (dep,-1,sizeof (DEP));
     int l=1,r=0;
     int i;
     r++;
     Q[r]=d;
     dep[d]=0;
          while (l<=r) {d=q[l];
               for (i=head[d];i!=0;i=a[i].next) {int t=a[i].t;
                    if (dep[t]==-1&&a[i].f>0) {dep[t]=dep[d]+1;
                    r++;
               q[r]=t;
     }} l++;
     } if (Dep[p]!=-1) return true;
return false; Inline double dfs (int d,double s) {
     if (d==p) return s;
     Double ts=s;
     int i;
          for (i=head[d];i!=0;i=a[i].next) {int t=a[i].t;
               if (dep[t]==dep[d]+1&&a[i].f>0) {double Tx=dfs (t,min (a[i].f,s));
               S-=TX;
               A[I].F-=TX;
               if (i%2==0) a[i-1].f+=tx;
          else A[i+1].f+=tx;
} return ts-s;
     Inline double dinic () {double s=0;
     while (BFS (0)) S+=dfs (0,2100000000);
return s;
     int main () {int n,m;
     scanf ("%d%d", &n,&m);
     int i,j;
     Double sum=0;
          for (i=1;i<=n;i++) {scanf ("%lf", &aa[i]);
     Sum+=aa[i];
	 for (i=1;i<=m;i++) scanf ("%lf", &bb[i));
	 for (i=1;i<=m;i++) for (j=1;j<=n;j++) scanf ("%d", &map[i][j]);
	 Double l=0,r=5000000;
	 p=n+m+1;
	 	  while (l<=r) {memset (a,0,sizeof (a)); memset (head,0, sizeof (head));
	      edge=0;
	      Double mid= (l+r)/(double) 2;
	      Double flow;
	           for (i=1;i<=m;i++) {flow=mid*bb[i];
	           edge++;
	           Add (0,i,flow);
	           edge++;
	      Add (i,0,0);
	                for (i=1;i<=m;i++) {for (j=1;j<=n;j++) {if (map[i][j]==1)
	                     {edge++;
	                     Add (i,j+m,2100000000);
	                     edge++;
	                Add (j+m,i,0);
	           }}} for (i=1;i<=n;i++) {edge++;
	           Add (I+m,p,aa[i]);
	           edge++;
	      Add (p,i+m,0);
	      Double Tt=dinic ();
	      if (tt+eps>=sum) r=mid-0.0001;
	 else l=mid+0.0001;
     printf ("%lf\n", L);
return 0; }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.