SER12
QUESTION DESCRIPTION
There is a classroom which has
M
M rows of benches in it. Also,
N
N students will arrive one-by-one and take a seat.
Every student has a preferred row number(rows are numbered
1
1 to
M
M and all rows have a maximum capacity
K
K. Now, the students come one by one starting from
1
1 to
N
N and follow these rules for seating arrangements:
Every student will sit in his/her preferred row(if the row is not full).
If the preferred row is fully occupied, the student will sit in the next vacant row. (Next row for N will be 1)
If all the seats are occupied, the student will not be able to sit anywhere.
Monk wants to know the total number of students who didn't get to sit in their preferred row. (This includes the students that did not get a seat at all)
Mandatory to use loop condition as "while(x!=y)"
Input
First line contains 3 integers
N
N,
M
M and
K
K.
N
N - Number of students and
M
M - Number of rows and
K
K - maximum capacity of a row.
Next line contains
N
N space seperated integers
A
i
Ai.
A
i
Ai - preferred row of
i
t
h
ith student.
Output
Output the total number of students who didn't get to sit in their preferred row.
There is a classroom which has
M
M rows of benches in it. Also,
N
N students will arrive one-by-one and take a seat.
Every student has a preferred row number(rows are numbered
1
1 to
M
M and all rows have a maximum capacity
K
K. Now, the students come one by one starting from
1
1 to
N
N and follow these rules for seating arrangements:
Every student will sit in his/her preferred row(if the row is not full).
If the preferred row is fully occupied, the student will sit in the next vacant row. (Next row for N will be 1)
If all the seats are occupied, the student will not be able to sit anywhere.
Monk wants to know the total number of students who didn't get to sit in their preferred row. (This includes the students that did not get a seat at all)
Mandatory to use loop condition as "while(x!=y)"
Input
First line contains 3 integers
N
N,
M
M and
K
K.
N
N - Number of students and
M
M - Number of rows and
K
K - maximum capacity of a row.
Next line contains
N
N space seperated integers
A
i
Ai.
A
i
Ai - preferred row of
i
t
h
ith student.
Output
Output the total number of students who didn't get to sit in their preferred row.
TEST CASE 2
INPUT
INPUT
7 2 2
1 1 2 1 1 7 1
OUTPUT3
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N,M,K;
cin>>N>>M>>K;
int x;
int occupied[M+1], nextrow[M+1], ans=0;
for(int i=1; i<=M; i++)
{
nextrow[i]=i;
occupied[i]=0;
}
bool flag=0;
for(int i=0; i<N; i++)
{
cin>>x;
if(!flag)
{
if(occupied[x]<K)
{
occupied[x]++;
}
else
{
if(occupied[nextrow[x]]<K)
{
occupied[nextrow[x]]++;
ans++;
}
else
{
int y=(nextrow[x])%N+1;
while(true)
{
if(y==x)
{
flag=1;
ans++;
break;
}
else
{
if(occupied[y]<K)
{
occupied[y]++;
ans++;
while(x!=y)
{
nextrow[x]=y;
x=(x)%N+1;
}
break;
}
else
{
y=y%N+1;
}
}
}
}
}
}
else
{
ans++;
}
}
cout<<ans<<endl;
return 0;
}
Hotel Casino de Monte-Carlo Casino - Mapyro
ReplyDeleteHotel Casino de Monte-Carlo is 양산 출장샵 a 4-star hotel with 용인 출장마사지 2,000 guest rooms and 수원 출장안마 villas located in the center. The Casino is situated 양산 출장안마 within 6 km (15 mi) 서귀포 출장안마 of Casino de Monte-Carlo,