# COGS729 Round Table Dinner

Source: Internet
Author: User

Problem Description:
assume that there are representatives from different units of M participating in an international conference. The number of delegates per unit is
ri (I=1,2,3...M),. The Conference restaurant has a total of n tables, each dining table accommodates c I (I=1,2...N) delegates.
in order to make the delegates fully communicated, it is hoped that representatives from the same unit will not dine at the same table. Try to design an algorithm,
give a representative dining plan that meets the requirements.
for a given number of delegates and tables as well as table capacity, programming is calculated to meet the requirements of the representative dining plan.
«Data Entry:
the input data is provided by the file roundtable.in. The 1th line of the file has 2 positive integers m and n,m represents the number of units, n table
table number, 1<=m<=150, 1<=n<=270. The 2nd line of the file has m positive integers representing each unit
number. The 3rd line of the file has n positive integers representing the capacity of each table.
«result output:
at the end of the program, the meal plan will be output to the file roundtable.out. If the problem has a solution, the file
1 Line Output 1, otherwise output 0. The next M-line gives the table number represented by each unit. If you have more than one meeting to
Solution , as long as the output of 1 scenarios.
Example output file for input file sample
roundtable.in

`45453535264         `

Roundtable.out

`112451234524512345 `

Maximum flow problem.

The source point S is connected to all units, the capacity is the number of units;

Each unit is attached to all tables and has a capacity of 1 (only one person can be assigned);

Each table to the meeting point T edge, capacity for the table can accommodate the number of people;

Run the maximum flow, if it can be full flow, indicating that the problem has a solution.

Check each edge, record which tables each unit sent to, and then output the answer.

`1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <queue>6#include <vector>7 using namespacestd;8 Const intmxn= the;9 intRead () {Ten     intx=0, f=1;CharCh=GetChar (); One      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} A      while(ch>='0'&& ch<='9') {x=x*Ten-'0'+ch;ch=GetChar ();} -     returnx*F; - } the structedge{ -     intu,v,nxt,f; -}e[mxn*Ten]; - inthd[mxn],mct=1; + voidAdd_edge (intUintVintf) { -E[++MCT].V=V;E[MCT].U=U;E[MCT].F=F;E[MCT].NXT=HD[U];HD[U]=MCT;return; + } A intn,m; at ints,t; - intD[MXN]; - BOOLBFS (intSintt) { -queue<int>Q; -memset (D,0,sizeofd); -d[s]=1; in Q.push (s); -      while(!Q.empty ()) { to         intu=Q.front (); Q.pop (); +          for(intI=hd[u];i;i=e[i].nxt) { -             intv=e[i].v; the             if(!d[v] &&e[i].f) { *d[v]=d[u]+1; \$ Q.push (v);Panax Notoginseng             } -         } the     } +     returnD[t]; A } the intDFS (intUintLim) { +     if(u==t)returnLim; -     inttmp,f=0; \$      for(intI=hd[u];i;i=e[i].nxt) { \$         intv=e[i].v; -         if(d[v]==d[u]+1&&e[i].f) { -tmp=DFS (V,min (LIM,E[I].F)); thee[i].f-=tmp; -e[i^1].f+=tmp;Wuyilim-=tmp; thef+=tmp; -             if(!lim)returnF; Wu         } -     } Aboutd[u]=0; \$     returnF; - } -InlineintDinic () { -     intres=0; A      while(BFS (s,t)) res+=DFS (s,1e9); +     returnRes; the } - intR[MXN],C[MXN]; \$vector<int>TO[MXN]; the intMain () the { theFreopen ("roundtable.in","R", stdin); theFreopen ("Roundtable.out","W", stdout); -M=read (); n=read (); in     inti,j; the     intsmm=0; the      for(i=1; i<=m;i++) R[i]=read (), smm+=r[i];//number About      for(i=1; i<=n;i++) C[i]=read ();//Table Capacity thes=0; t=n+m+1; the      for(i=1; i<=n;i++) {//Dining Table the Add_edge (S,i,c[i]); +Add_edge (I,s,0); -     } the      for(i=1; i<=m;i++){Bayi          for(j=1; j<=n;j++){ theAdd_edge (J,i+n,1); theAdd_edge (I+n,j,0); -         } -     } the      for(i=1; i<=m;i++){ theAdd_edge (i+n,t,r[i]); theAdd_edge (T,i+n,0); the     } -     intans=dinic (); the     if(ANS!=SMM) {printf ("0\n");return 0;} the      for(i=2; i<=mct;i++){ the         if(e[i].f && e[i].u!=s && e[i].u!=t && e[i].v!=s && e[i].v!=t && e[i].u>e[i].v) {94to[e[i].u-N].push_back (E[I].V); the         } the     } theprintf"1\n");98      for(i=1; i<=m;i++){ About          for(j=0; J<to[i].size (); j + +){ -printf"%d", To[i][j]);101         }102printf"\ n");103     }104     return 0; the}`

COGS729 Round Table Dinner

Related Keywords:

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.