Abstract: queue "jam" is a behavior that causes people's strong dissatisfaction, but this phenomenon often exists. In the bank's single window queuing problem, it is assumed that the bank has only one window to provide services, and all customers are arranged in a long line according to the arrival time. When the window is free, the next customer will go to the window to process the transaction. At this time, if it is known that the i-th customer and the j-th customer are good friends, and they are willing to handle affairs for their friends, then the transaction processing time of the i-th customer is the sum of their own affairs and that of their friends' affairs. In this case, the waiting time of customers may be affected. Suppose that when all the people arrive at the bank, if there is no empty window, they will ask for the help of the friends at the top (including the friends who are receiving the service at the window); when there is more than one friend asking for the help of a customer, the customer will act on the Council according to the order of their friends' requests. Try to write a program to simulate this phenomenon and calculate the average waiting time of customers.
A simulation problem, first of all to understand their own ideas, otherwise this problem will be difficult to pass.
Let's talk about the place where they are trapped: Although the two people belong to the same circle, the second person may not have arrived after the first person completes the business, so we will not consider the second person any more and let him go to line up honestly;
Here is the AC code with some necessary comments:
#include <bits/stdc++.h> using namespace std; const int maxn=10000+10; struct node { string name; int arrive,work; }que[maxn]; int main() { int n,m; cin>>n>>m; vector<string> friends[maxn]; map<string, int> number; //Record who is in each circle. The one-dimensional coordinate of vector represents the circle number for(int i=1;i<=m;i++) { int num; cin>>num; for(int j=0;j<num;j++) { string s; cin>>s; number[s]=i; friends[i].push_back(s); } } map<string,int> norder;//Read in the normal order; for(int i=1;i<=n;i++) { string s; int a,b; cin>>s>>a>>b; que[i].name=s,que[i].arrive=a,que[i].work= b>=60? 60 : b; norder[s]=i; } vector<int> reorder[maxn];//Record the order of individuals in each circle for(int i=1;i<=m;i++) { for(int j=0;j<friends[i].size();j++) { int x=norder[friends[i][j]]; reorder[i].push_back(x); } sort(reorder[i].begin(),reorder[i].end()); } bool vis[maxn]; memset(vis,false,sizeof(vis)); int time=0,ans=0; for(int i=1;i<=n;i++) { if(vis[i]==true) continue; vis[i]=true; cout<<que[i].name<<endl; if(que[i].arrive>=time) time=que[i].work+que[i].arrive; else { ans+=time-que[i].arrive; time+=que[i].work; } int x=number[que[i].name]; for(int j=0;j<reorder[x].size();j++) { int t=reorder[x][j]; if(vis[t]==true) continue; if(que[t].arrive<=time)//If the first person in a circle finishes the work and the second person doesn't arrive, they don't think about it { vis[t]=true; ans+=time-que[t].arrive; time+=que[t].work; cout<<que[t].name<<endl; } } } printf("%.1f",ans*1.0/n); return 0; }