Topic 1334: occupying seats
time limit:1 seconds
Memory limit:32 MB
Special question: No
submitted:737
Resolution:174
-
topic Description:
-
sun's classroom seats are available every day at the school where they are located.
One person can take up multiple seats, and must be a continuous seat, and if he does not occupy as many seats as he requires, then he will not have a seat. In order to reduce the difficulty, each allocation of seats according to the seat number from small to large search, using the first adaptation method to allocate seats.
-
Input:
-
Enter more than one set of data.
Each group of data entered the number of seats n,0<n<=100 (the number of seats is equal, the seats are sorted from left to right in each row), M (0<m<=min (100,n*n)) individuals.
then enter K (0<k<=100), and finally enter the K command.
There are only two types of commands:
1.in ID num (on behalf of ID,0<=ID<M, to occupy Num seats, if no consecutive num (0<num<=20) seats indicate that the command is invalid)
2.out ID (represents the ID to release all the seats he took before)
Note: If the ID has not been released before the seat has been taken, then his in command is invalid,
If the ID did not occupy the seat before, then his out command is also invalid.
-
Output:
-
Output yes or no for each in command, output Yes if the command is valid, output no if invalid.
Only the carriage return, without any other characters, is followed by Yes.
-
Sample input:
-
4 109in 1 7in 2 3in 3 3in 3 3in 4 3out 2in 5 6out 3in 5 6
-
Sample output:
-
Yesyesyesnoyesnoyes
Do the subject carefully and carefully, and then carefully. AC Code 60MS
#include <iostream> #include <string.h> #include <stdio.h>using namespace std;typedef struct node{int Start int end;} Node;node C[101];char A[10010];char In[101];char out[101];char op[5];int Main (int argc, char *argv[]) {int n,m; int id; int k; Freopen ("1334.in", "R", stdin); while (~SCANF ("%d%d%d", &n,&m,&k)) {memset (c,0,sizeof (c)); memset (A,0,sizeof (a)); memset (In,0,sizeof (in)); Memset (out,0,sizeof (out)); for (int i=1;i<=k;++i) {scanf ("%s", op); if (strcmp (OP, "in") ==0) {int num; scanf ("%d%d", &id,&num); if (in[id]==0)//did not participate in {//have a try int cnt=0; int tt; int flag=0; for (TT=1;TT<=N*N;++TT) {if (a[tt]==0) {cnt++; if (cnt==num) {flag=1; printf ("yes\n"); c[id].start=tt-num+1; C[id].end=tt; printf ("Start%d end%d\n", c[id].start,c[id].end); in[id]=1;//sign participated in the out[id]=0; for (int k=c[id].start;k<=c[id].end;++k) a[k]=1;//occupy position Break }} else if (a[tt]==1) cnt=0; } if (!flag) printf ("no\n"); } else {//has already participated in printf ("no\n"); }} else {scanf ("%d", &id); if (out[id]==0) {in[id]=0; Out[id]=1; int S=c[id].start; int e=c[id].end; for (int i=s;i<=e;++i) a[i]=0; }}}} return 0;}
Nine degrees OJ 1334 seats (analog care)