1 条题解

  • 3
    @ 2021-8-7 20:26:21

    C++ :

    #include <iostream>
    #include <cstdio>
    #include <queue>
    #define N 1005
    #define M 1000005
    using namespace std;
    
    int n, cnt;
    int tem[M];
    queue<int> mai, zero;
    queue<int> a[N];
    
    int read()
    {
    	int x = 0; char c = getchar();
    	while(c < '0' || c > '9') c = getchar();
    	while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
    	return x;
    }
    
    int main()
    {
    	while(scanf("%d", &n) == 1)
    	{
    		if(!n) break;
    		printf("Scenario #%d\n", ++cnt);
    		mai = zero;
    		for(int i = 1; i <= n; i++) a[i] = zero;
    		for(int i = 1; i <= n; i++)
    		{
    			int num = read();
    			for(int j = 1; j <= num; j++)
    				tem[read()] = i;
    		}
    		while(1)
    		{
    			char c[10]; scanf("%s", c);
    			if(c[0] == 'E')
    			{
    				int x = read();
    				if(!a[tem[x]].size()) mai.push(tem[x]);
    				a[tem[x]].push(x);
    			}
    			else if(c[0] == 'D')
    			{
    				int id = mai.front();
    				printf("%d\n", a[id].front());
    				a[id].pop();
    				if(!a[id].size()) mai.pop();
    			}
    			else if(c[0] == 'S') break;
    		}
    		printf("\n");
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    43
    时间
    1000ms
    内存
    128MiB
    难度
    1
    标签
    递交数
    98
    已通过
    70
    上传者