! Q9 o8 H! z; |1 ]) Xif(m_que.empty())! m2 d T/ T# I
{ \. u6 ^8 Y, i: t
min = 0; 8 Z, }' r; Y. z# c/ Ifor(int index2 = 1; index2< m_s_count;index2++)! n: t1 D( p o `/ L
if(m_s_array[min].times > m_s_array[index2].times) : r$ H4 ]8 m7 n% K7 U$ d. ^min = index2; U) f) x7 y/ U6 H* r. U/ A- E. f8 G A$ A$ f6 @
if(m_s_array[min].times+durtime>copy_end_time)& f% l9 [- w. b: y0 f
{& q+ I2 E) g+ e# @5 T
c_flag = 1; + v$ C7 \5 g' e& n: g1 t) v% ycout<<"时间不够,不能接受烫发服务"<<endl<<endl; 7 F3 m0 u$ k3 l}" z y0 h6 G- Q" j( W
}//if ! H; A& S `- N* u- f1 k, X$ D" Nelse9 w! b! s5 i* r% f* n6 z1 r i
{ 4 h- V# c" C$ f. h0 [! Ktemp_m.clear();+ j. H& ]0 P& d9 \/ _
for(int index = 0;index<m_s_count; index++) , Y2 K* ? g9 {5 o Gtemp_m[index] = m_s_array[index].times; 4 ]+ ^# j5 H3 A2 l' R" m8 x* ]; c0 ^/ v2 n- G% F; D
int count_tem_w_c_que = 0;: ^0 y. _$ u; U' F
$ `: W$ {! l) G
for(int index1 = 0;index1<m_que.size();index1++)//预计烫发队列中的人要完成服务的最少时间9 X2 m! J9 }3 Z" e. ^) m$ H5 Z
{; `: a1 Z7 ]0 O# ?
min = 0; 4 V/ X# _; {( A: a5 r$ y6 u, a& N7 Gfor(int index2 = 1; index2< m_s_count;index2++) 6 J$ O* F' ^9 E2 } i8 }. T- {* fif(temp_m[min] > temp_m[index2]) 7 i O' x8 {/ `) @5 Z2 ~min = index2; 4 H, c! m; S8 j, U& W( Ztemp_m[min] += tem_w_c_que[count_tem_w_c_que++]; 2 W2 j. e- J* `6 N# {} 7 w9 x; D" [% q3 |) G+ y1 mmin = 0;8 E- J1 L( O- W3 w! G: m) b
for(int index2 = 1; index2< m_s_count;index2++)& p% T7 ` i' D
if(temp_m[min] > temp_m[index2]) 2 i; q4 U, ^/ Vmin = index2;9 ]' T, e. |1 W2 E! E6 F: C
% t. b( S. ^& n+ k( I! R ]$ d7 g; g3 K
if(temp_m[min]+durtime > copy_end_time); R4 e: A4 y4 p' i x
{* r, C' I; E. h: ~5 o& w& Q
c_flag = 1; . n w0 ? z# N! I% @7 ?, ycout<<"时间不够,不能接受烫发服务"<<endl<<endl;+ n( |0 U4 @! U
} + N/ x- a# ]9 N: P' E* F3 I+ h. @& d; |8 ~, d
+ E) [5 V) K4 l0 _. z$ ~}//else 4 D9 K- ^( `0 U}//else_if ' P% S: Q/ M# F5 V' r 6 o2 S5 i( M sif(c_flag==0), P/ x, R1 n/ R$ ?/ i
{. a8 d$ o) ^9 F4 `
if(i==0 || i==1) ( |( X8 z( o1 ]" o{2 |" P+ G3 I/ e! n1 ]7 O7 R
j=0; * V+ ~! U+ i$ F, M" Y$ Z
while(j<h_c_s_count) - a3 w/ |$ x7 Q{ 9 Y' m' h' M1 [if(h_c_s_array[j].flag == 0) ' x6 A, ?! \# U c4 E0 V{! a6 j) J; r. x B* l
cout<<"客人"<<count<<"坐的是 "<<j<<"号理发或者洗发位置"<<endl;2 p3 x' K K% j. ^; o% W# ~+ @
h_c_s_array[j].begin_time = copy_end_time;/ n7 M) w/ ]( S9 f, O/ Z
h_c_s_array[j].flag=1;$ _/ j% X: p9 k! J
h_c_s_array[j].times = durtime;3 T" A x% P9 t, L
h_c_s_array[j].price = t_array[i].price;& l! [# \" [& Y3 V2 y! ^
h_c_s_array[j].number = i; * p$ R8 q( P! R- l# @h_c_s_array[j].count = count;7 X8 F m! A% c1 U; R8 G/ A
break;# Y6 k6 n. Z- S6 c
}3 t, \0 S9 L4 l
j++; 7 X& }! b( [$ _( L4 U5 R% |}- C7 D1 z; V$ c% n9 x+ ~6 q- k( H
if(j==h_c_s_count)( m2 g6 V t8 F+ f% L2 F
{' ^! Y$ A/ j9 N1 o4 n, e
cout<<"理发或洗发位置满了,请等一等"<<endl; 4 `: l& r9 J0 O. Qa.arriver_time = copy_end_time;) |% a- U2 p. ]# U4 }9 s- I
a.times = durtime; 4 s1 O( H8 ?, n0 da.number = i; ) M/ I& m5 C, }- w2 K" xa.count = count; * \+ J& o! v U- zw_c_que.push(a);3 ~, g4 u3 ^& H, X; I, A* r0 E
que_long += w_c_que.size();/ V: S9 |0 p d
que_change++;0 x) g I1 ]/ B7 V; Y% `4 D
} % Y* i! H6 R! u# h" L3 j4 X( |8 @}//if & ^; _6 O# h b8 g9 Q. yelse if(i==2)# M9 i" M) N+ n q4 P* W1 q( D
{0 m8 Y7 L/ J/ m% F9 n( Y0 E! j$ ?
z=0; . ~5 w0 N" F* \: swhile(z<m_s_count)9 `) h+ y t5 n/ |9 p/ T9 p
{# R+ n" a! G+ v; v( D4 B
if(m_s_array[z].flag == 0) 9 h, v" q# p( g$ H' q{ $ C F4 _% L+ Lcout<<"客人坐的是 "<<z<<"号烫发位置"<<endl;: a1 P% M* y# \' {* @8 S' }- K3 a
m_s_array[z].flag = 1;5 O& K h8 x' p( C
m_s_array[z].begin_time = copy_end_time;# v% w) i6 T* D# \
m_s_array[z].times = durtime;$ \* o) y* W0 A" j; u9 O
m_s_array[z].count = count; # ^( f; X5 ^6 x8 v; a0 Pm_s_array[z].price = t_array[i].price;- M% c2 R9 _% P7 {: A [! Y z
break; 4 G0 w) F9 `8 y K}- ~& {$ P: ~* Y6 F1 i( ?$ t
z++; + V# h p. r1 H+ A* J9 H: m6 H} * O/ R5 ]4 V6 ^2 \! M \if(z == m_s_count)$ E9 i/ S3 {6 q% k+ c2 X6 q/ E
{ 7 a4 w2 `$ L1 h# `: s4 s. scout<<"烫发位置满了,请等一等"<<endl;* B/ k, c; N7 C0 ]" `8 D0 a+ A
a.arriver_time = copy_end_time; 1 B. ? Y$ e- }* Ta.times = durtime; 5 j, T# \& x+ D, Z$ H0 Y$ Ia.count = count; q4 b- |; b8 v2 Q0 Da.number = i; ( v+ Z% g2 K6 Z1 pm_que.push(a); . m: G4 i- r2 x6 s. \! E1 sque_long += m_que.size();3 N6 W2 P4 c( Y' ~; E9 P8 L
que_change++;2 J2 q- H, z& l( Q+ M
} N2 @ {3 t; R: Q7 d) j: O}//else if! z) B% x# A( |* X% H1 b
}//if3 J% p6 L) ]6 \ [
c_flag=0; * c$ J2 h; a, d1 F" A0 }7 s}//if* x E; w$ ~3 ~
for(int index = 0;index<h_c_s_count;index++)6 A( G. t# N! [3 N8 }3 C
{$ O/ T( n0 N3 g3 O
if(h_c_s_array[index].flag==1 && h_c_s_array[index].times>0)$ e" N: N6 e( F: t( M; E
{; q9 C% K! t% e. W0 u9 Y! k) V I
--h_c_s_array[index].times;, R3 t- t9 {+ _1 r5 ~
if(h_c_s_array[index].times == 0)+ m$ u; |9 l7 ~+ h0 y, p
{ 9 r9 G8 G2 y/ [( d' Ksum_cousterm++; $ t, r3 ^. E3 }$ v4 C vif(h_c_s_array[index].number == 0): v, K" h G$ w4 Z
{ & v6 H: U2 Y, Z2 d5 P9 a+ @- U9 Dcout<<"座位号"<<index <<"的客人"<<h_c_s_array[index].count<<"的洗发服务完成了"<<endl; 4 |2 K8 D( F& x! A. D- Jcout<<"这个客人逗留了"<<h_c_s_array[index].begin_time - copy_end_time+1<<"分"<<endl;% D: T# e+ N8 ` l, v% [
h_c_s_array[index].number = -1;) d! c* o) {# ~, ]5 V$ I
sum_time += h_c_s_array[index].begin_time - copy_end_time+1;2 o, P2 E- [ c6 b& p* W
}# p% B" S" V# R% ?. h
else if(h_c_s_array[index].number == 1)3 P! i1 q$ @& Y2 l% ]% ?
{ - \6 x: y) m4 }cout<<"座位号"<<index <<"的客人"<<h_c_s_array[index].count<<"的理发服务完成了"<<endl;' o0 \$ U4 l9 ^" O% P
cout<<"这个客人逗留了"<<h_c_s_array[index].begin_time - copy_end_time+1<<"分"<<endl;* u8 M" u3 f" F- A6 R
h_c_s_array[index].number = -1;1 q+ h& B3 ~4 o+ U
sum_time += h_c_s_array[index].begin_time - copy_end_time+1;1 |' g, P @& V5 h1 [) a+ h! e
} 8 N% Z2 L0 |6 ~0 gcout<<"总共完成 "<<sum_cousterm<<" 客人的服务"<<endl; U& ^7 F5 \5 ]
h_c_s_array[index].count = 0;9 i$ n/ e9 W( |2 u2 }
sum_earn += h_c_s_array[index].price;6 U- _* V2 r: a
cout<<"总共赚了:"<<sum_earn<<endl;% f d2 z4 o; }7 P
h_c_s_array[index].flag = 0; : n' N% v4 {9 e* C4 v2 }' l/ w: Rh_c_s_array[index].times=0;$ X7 Q/ K- n/ e2 ~+ D
cout<<"理发或者洗发"<<index<<"号位置空了"<<endl; 8 n+ ^% H1 S5 H. k; I/ a' F/ q! Y
% M! z% o3 H4 g9 z5 p6 s! b" ~if(!w_c_que.empty())( G q% z( X2 W8 `4 Q* y
{" F |' C3 N) b; Z: r
if(w_c_que.front().number == 0)6 M2 T- d. y9 [1 k0 Y4 B
{/ m9 g4 ?" I6 ^! P
cout<<"等待洗发队列中的客人 "<<w_c_que.front().count<<" 号去 "<<index<<" 号理发或者洗发位置开始接受洗发服务"<<endl; + n ^$ c) r# f# N' V* s Wh_c_s_array[index].flag=1; / ^1 C9 G3 C9 L% y7 f6 [h_c_s_array[index].begin_time = w_c_que.front().arriver_time;( @0 A; {/ C2 m* k; b
h_c_s_array[index].times = w_c_que.front().times; " m: C. b% x2 oh_c_s_array[index].price = 5;% \- u3 t% I: m# v
h_c_s_array[index].number = w_c_que.front().number;9 P8 o7 \* B2 x' _8 F( }
h_c_s_array[index].count = w_c_que.front().count; / [" a, A4 I4 `' g8 }w_c_que.pop(); ! G6 N5 E: f9 F/ |1 \$ mque_long += w_c_que.size(); ; w5 s8 G( T k1 pque_change++;( F2 I& k/ r, k+ o ^
} / V0 m4 H/ k' o5 pelse if(w_c_que.front().number == 1)/ f% j: h# v: T: O1 X* C
{ 0 [" q2 E' e" B5 e. Z2 scout<<"等待理发队列中的客人"<<w_c_que.front().count<<" 号去 "<<index<<" 号理发或者洗发位置开始接受理发服务"<<endl; 3 m! W$ g( q2 F H1 i' G6 N. Q! k1 k, yh_c_s_array[index].flag=1;# j1 ]/ s1 ?! l* T8 z
h_c_s_array[index].begin_time = w_c_que.front().arriver_time;5 c9 ^/ h6 d# G) y* M1 z/ w* `
h_c_s_array[index].times = w_c_que.front().times;4 {" n+ `2 V, P# G
h_c_s_array[index].price = 10; & o, c6 D6 k4 R$ H3 R9 [1 ah_c_s_array[index].number = w_c_que.front().number; ; T* N9 e. G% ~- ]/ |3 kh_c_s_array[index].count = w_c_que.front().count;$ J. U# L, q' U1 r5 \
w_c_que.pop();- Y- J9 f# c( Q
que_long += w_c_que.size(); : x' C7 ?/ J' G5 o [3 eque_change++;+ p) d: u4 D: d- ]/ i$ I4 M
} $ X; M, x9 g9 P}//if 8 k& k. T" G2 v4 g/ {9 O}//if6 B; j# Y! i- J6 h! t
}//if + I9 I8 n. y N. q}//for 3 E$ Z6 n2 @9 |# B" a l4 w 2 B+ o$ `1 R2 r }' |for(index = 0;index<m_s_count;index++)% H, `4 ^5 y6 D2 X' e2 ?8 o% I% Q
{7 I& Z, a9 e% q7 B; ~& \. s
if(m_s_array[index].flag==1 && m_s_array[index].times>0)* @# T5 O7 } i: a. {
{ " }0 b. L* R+ R, r2 P; t--m_s_array[index].times ;7 ?* I6 W" [1 J% D+ s: |. I9 b
if(m_s_array[index].times == 0)7 e( ~+ {( {0 I
{8 k6 L* ^/ i- T9 ^9 _2 {
cout<<"座位号"<<index <<"的客人"<<m_s_array[index].count<<" 烫发服务完成了"<<endl;0 Z( J9 H) X* w# E. c; H7 E
cout<<"这个客人逗留了"<<m_s_array[index].begin_time - copy_end_time+1<<"分"<<endl; 0 U' \7 a9 K/ u& o: S, ssum_cousterm++; ; ?* J1 A2 M Y( ecout<<"总共完成 "<<sum_cousterm<<" 客人的服务"<<endl; . T7 m: q8 r2 Q9 _% F7 A! Tsum_earn += m_s_array[index].price;, `( m/ O1 |9 P
cout<<"总共赚了:"<<sum_earn<<endl;% {5 z7 _& V; G0 \: x K- b2 e7 c
m_s_array[index].flag = 0;: W3 |+ X* q" W9 c& p% X9 P
m_s_array[index].times = 0;* K8 S4 e/ L* T$ m5 a, K9 d& K
m_s_array[index].count = count; & D. W2 q3 N. n/ I5 Y! n F4 \1 Zsum_time += m_s_array[index].begin_time - copy_end_time+1; 3 A0 ^+ k+ l6 e" z$ [! x( j4 lif(!m_que.empty())4 t. z: f9 Y9 k5 O" E9 Q
{ + c4 g3 x [% j# e5 \: k- acout<<"等待烫发的客人"<<m_que.front().count<<"开始去"<<index<<"号烫发位置接受服务"<<endl; * d. c/ A8 t( bm_s_array[index].flag=1;9 {) R- V8 H9 N% ~+ l5 \$ L o
m_s_array[index].times = m_que.front().times;) N) k/ m, E- ?
m_s_array[index].price = 40;7 d3 H2 q7 A/ [2 G' R3 `3 I9 n X3 i
m_s_array[index].begin_time = m_que.front().arriver_time;- Z) k5 f7 J( r2 Y8 Z/ |: I
m_s_array[index].count = m_que.front().count; 8 v" B! A& d, u1 jm_que.pop();5 h X9 x. d6 w( d- m7 n
que_long += m_que.size(); % Y' n* A' h1 c! X7 Cque_change++;7 u0 i: B! s/ B
} & G% v* ]$ k1 K P0 ^7 p0 k}+ j8 q" y$ W5 {! d+ r$ Z
} 8 m) v+ O- i1 q; i}8 S: L) E: H6 R8 C) o1 i' B6 f
copy_end_time--;5 E3 S) [; U2 }- k X
cout<<"还有 "<<copy_end_time<<" 分就关门了"<<endl; & g+ ]0 o& U* A, Xcout<<endl; . V- y5 ~+ y1 H+ f) p; Pfor(int t = 0;t <50000000;t++); ; F' Q* {6 t3 d$ ?$ Yif(flag==0&&intertime>0) $ r. R+ v% P; X% Wintertime--; r2 ^" @$ V4 r' D, o+ C1 [7 Q
}//while0 C9 L" k1 | _. t! {
}( W& r3 l; {" w9 P4 D& C+ M" f
2 a6 o' \0 u0 S/ T3 Z* v
int hair_cut_shop::average_queue_long() ! w7 q, a& Y0 n1 Y8 W{+ B# X$ y- _% b! u$ g% i$ O
return static_cast<int>(que_long / que_change);4 y q8 M, Y$ k# b2 z6 p, S
}) l. w; V# w4 z) ~
7 x* E% u A! g$ Qfloat hair_cut_shop::stay_time()4 {( p7 r. g4 g/ ~# L% g3 x7 k
{; m( Z+ e9 N2 Q( T3 n) p' V
return static_cast<float>(sum_time/sum_cousterm); 3 h9 E# G# C D- V- i} + d; g) x" q+ Q* u% \' p* Nvoid hair_cut_shop::display(ostream &out) + o U4 V) e" f{ ) E7 n# E5 N5 S( C3 v" O& Rout<<"总共赚 "<<sum_earn<<"元"<<endl; - D$ c- A }+ P6 ?( u2 S$ O% bout<<"平均队列长度是:"<<average_queue_long()<<endl; 6 b) x) V; e2 ~" q6 N3 h. Fout<<"顾客平均逗留时间:"<<stay_time()<<endl;" `9 d2 t1 @; x- P+ S& U
}+ ?" M' |7 X! N8 k! a1 U& M! p- F
) F8 l4 G0 {# \7 s' j q Xvoid main()) c9 Y1 }9 K- C. N& g6 X5 X7 l
{2 C9 J' B: B: U' _. f# c2 P
int m,n; ; m. ?# \) v: x2 y7 G$ |8 Z# J# h( {, lcout<<"请输入理发位置的个数"<<endl; 2 L$ Q6 p7 @9 Y& x2 H; u( _9 Rcin>>m; - m3 W% D% m8 vcout<<"请输入烫发位置的个数"<<endl;( M8 U# o' p0 x; E3 u, H z: O0 ?2 V
cin>>n;3 p" L, G- s$ ?
cout<<endl;% e- u# ~( b+ ?7 K" z