Hdu2883kebab (maximum flow ISAP) discretization thought building map

Source: Internet
Author: User

KebabTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1145 Accepted Submission (s): 472


Problem descriptionalmost Everyone likes kebabs nowadays (here a kebab means pieces of meat grilled on a long thin stick). However, considered about the hardship of a kebab roaster while enjoying the delicious food? Well, here's a chance for your help of the poor roaster make sure whether he can deal with the following orders without dis Satisfying the customers.

Now N customers is coming. Customer I'll arrive at time Si (which means the roaster cannot serve customer I until time Si). He/she would order NI kebabs, each one of the which requires a total amount of TI unit time-to-get it well-roasted, and want to Get them before Time ei (Just at exactly time ei is also OK). The roaster have a big grill which can hold an unlimited amount of kebabs (unbelievable huh? Trust me, it ' s real!). But he had so little charcoal, at a most M kebabs can is roasted at the same time. He is skillful enough to take no time changing the kebabs being roasted. Can him determine if he can meet all the customers ' demand?

Oh, I forgot to say so the roaster needs not to roast a single kebab in a successive period of time. That means he can divide the whole TI unit time to K (1<=k<=ti) parts such that any of the adjacent parts don ' t have To is successive in time. He can also divide a single kebab into K (1<=k<=ti) parts and roast them simultaneously. The time needed to roast one part of the kebab well was linear to the amount of meat it contains.so if a kebab needs unit time to roast well, he can divide it into the parts and roast them simultaneously just one Unit Time. Remember, however, a single unit time was indivisible and the kebab can only being divided into such parts so each needs an Integral unit time to roast well.

Inputthere is multiple test cases. The first line of all case contains, positive integers n and M. n is the number of customers and M are the maximum Keba BS The grill can roast at the same time. Then follow N lines each describing one customer, containing four integers:si (arrival time), ni (demand for kebabs), EI (deadline) and Ti (time needed for roasting one kebab well).

There is a blank line after each input block.

Restriction:
1 <= N <=, 1 <= M <= 1,000
1 <= ni, ti <= 50
1 <= si < ei <= 1,000,000

Outputif the roaster can satisfy all the customers, output "Yes" (without quotes). Otherwise, Output "No".
Sample Input
2 101 10 6 32 10 4 22 101 10 5 32 10 4 2

Sample Output
YesNo

Source2009 multi-university Training Contest 9-host by hit test instructions: There are N (<=200) customers, the first customer is a ni (<=50) grilled skewers, each skewers need to spend ti (<=5 0) A time unit, service time from Si (just start service) to EI (including ei time point), assuming a string needs to bake 10 units of time, then you can divide the string into 10 parts, every 1 parts as long as 1 units of time can be baked to the customer. Now barbecue racks at the same time can bake a maximum of M-string, ask can not serve all customers?
Analysis: Read the online problem solving, with the discretization of time to build the map. First of all, according to test instructions, each customer wants NI string into ni*ti parts, it is equivalent to a ni*ti string, each bine flowers 1 units of time. So now we're going to determine what the flow is, test instructions in the "barbecue rack inAt the same timeCan bake up tom-String, so when each of the points and sinks to build an edge, the capacity of M, not to see whether the time-out, the establishment of feasible solutions will be optimized. To determine the number of strings, we can put the   source point and each customer to build an edge, contents for the number of decomposition after the string ni*ti, and finally each customer and service time each point in time to build an edge, contents for >=ni*ti. After the completion, the scheme is feasible, but the point of time can reach 100W points, so it will time out, then you need to use discretization, each occurrence of the time point down to sort out the weight, assuming K (<=400) a different time point, then there will be k-1 time period, we can think of each time period as a point , the capacity of the customer and the time period within the required time can be unchanged (since each customer only needs to occupy Ni*ti grill), while the time period and the meeting point capacity need to change to m* (the length of the time period, excluding the starting point of the time period). This is built, the total number of points =1+n+ (k-1) +1. This will not time out.
#include <stdio.h> #include <string.h> #include <queue> #include <algorithm>using namespace std   ; #define Captype intconst int maxn = 100010;    Total number of points const int MAXM = 400010;    Total number of edges const int INF = 1<<30;struct edg{int to,next; Captype Cap,flow;}  Edg[maxm];int Eid,head[maxn];int GAP[MAXN];  The number of points for each distance (or can be considered a height) int DIS[MAXN];  The shortest distance from each point to the end Enode int CUR[MAXN];    Cur[u] indicates that from the U point can flow through the cur[u] number side void init () {eid=0; memset (head,-1,sizeof (Head));}    There are three parameters to the edge, 4 parameters void addedg (int u,int v,captype c,captype rc=0) without a forward edge {edg[eid].to=v; edg[eid].next=head[u]; Edg[eid].cap=c; edg[eid].flow=0;    head[u]=eid++; Edg[eid].to=u;    EDG[EID].NEXT=HEAD[V]; EDG[EID].CAP=RC; edg[eid].flow=0; head[v]=eid++;}    Preprocessing Enode points to all points at the shortest distance void BFS (int sNode, int enode) {queue<int>q;    memset (Gap,0,sizeof (GAP));    memset (dis,-1,sizeof (dis));    Gap[0]=1;    dis[enode]=0;    Q.push (Enode);        while (!q.empty ()) {int U=q.front (); Q.pop (); for (int i=head[u]; i!=-1;I=edg[i].next) {int v=edg[i].to;                if (dis[v]==-1) {dis[v]=dis[u]+1;                gap[dis[v]]++;            Q.push (v);    }}}}int S[MAXN];              Path stack, which is the ID number of the edge captype maxflow_sap (int snode,int enode, int n) {//NOTE: N is the total number of points, including the source point and the meeting point BFS (SNode, Enode);    Pre-Enode the shortest distance to all points if (dis[snode]==-1) return 0;    Source point to unreachable sink point memcpy (cur,head,sizeof (head));  int top=0;  Stack top Captype ans=0;    Max Stream int U=snode;            while (dis[snode]<n) {//determines from SNode point there is no flow to the next adjacent point if (u==enode) {//Find a way to add flow captype min=inf;            int inser; for (int i=0; i<top; i++)//To find the maximum amount of traffic Min if (min>edg[s[i]].cap-edg[s[i]].flow) {M) from this stream                In=edg[s[i]].cap-edg[s[i]].flow;            Inser=i;                } for (int i=0; i<top; i++) {edg[s[i]].flow+=min;  Edg[s[i]^1].flow-=min;            Flow of the side that can be recycled} ans+=min; Top=inser;  From the flow of this can be added to the flow of the bottleneck in the edge of the upper edge of the flow can be increased, so only from the fault of the traffic bottleneck cutting u=edg[s[top]^1].to;        The starting point of the traffic bottleneck edge is continue;  } bool flag = FALSE;        It is possible to determine whether an int v can flow toward the neighboring point from the U point;            for (int i=cur[u]; i!=-1; i=edg[i].next) {v=edg[i].to;                if (edg[i].cap-edg[i].flow>0 && dis[u]==dis[v]+1) {flag=true;                Cur[u]=i;            Break  }} if (flag) {s[top++] = Cur[u];            Add an edge u=v;        Continue        }//If a flow adjacent point is not found above, then the distance from the starting point U (which can also be considered a height) is the minimum distance of +1 int mind= n for the adjacent flow point;            for (int i=head[u]; i!=-1; i=edg[i].next) if (edg[i].cap-edg[i].flow>0 && mind>dis[edg[i].to]) {            MIND=DIS[EDG[I].TO];        Cur[u]=i;        } gap[dis[u]]--;  if (gap[dis[u]]==0) return ans; When Dis[u] The point of this distance is gone, it is impossible to find an augmented stream path from the source point//Because there is only one distance from the sink point to the current point, then from the source point to the sink point must pass the current point, but the current point is not able to find Can flow to the point, then the inevitable interruption of dis[U]=mind+1;        If a flow adjacent point is found, the distance is the adjacent point distance of +1, or n+1 gap[dis[u]]++ if it is not found;  if (U!=snode) u=edg[s[--top]^1].to; Return an Edge} return ans;    int findlocat (int *tm,int tn,int ti) {int l=0, r=tn-1, mid;        while (l<=r) {mid= (l+r) >>1;        if (Ti==tm[mid]) return mid;        if (Ti>tm[mid]) l=mid+1;    else r=mid-1; } return 0;} struct man{int stime,etime,kpart;}    Man[205];int Main () {int n,m, ni,ti;    int s, t, ans;    int time1[405],k;        while (scanf ("%d%d", &n,&m) >0) {k=0; s=0; ans=0;        Init ();            for (int i=1; i<=n; i++) {scanf ("%d%d%d%d", &man[i].stime,&ni,&man[i].etime,&ti);            Man[i].kpart = Ni*ti;            Ans + = Ni*ti;            Time1[k++]=man[i].stime;                        Time1[k++]=man[i].etime;        ADDEDG (S, I, ni*ti);        } sort (time1,time1+k);        int j=0; for (int i=1; i<k; i++) if (Time1[j]!=time1[i]) time1[++j]=time1[i];        k=j+1;        t=n+j+1;        for (j=1; j<k; j + +) Addedg (j+n, T, m* (time1[j]-time1[j-1]));            for (int u=1; u<=n; u++) {J=findlocat (time1, K, man[u].stime) +1;                while (time1[j]<=man[u].etime&&j<k) {addedg (U, J+n, Man[u].kpart);            j + +;        }} ans-=maxflow_sap (S, T, t+1); printf ("%s\n", ans>0?)    No ":" Yes "); }}


Hdu2883kebab (maximum flow ISAP) discretization thought building map

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.