#include<stdio.h>
#define DEBUG_IO (0)
const int MAX = 1005;
const int INF = 65535;
typedef struct Node
{
int x;
int age;
Node():x(0),age(0){}
};
enum Command
{
ADD_ONE = 1,
DEL_OLD = 2,
DEL_YOU = 3,
IS_OVER = -1,
};
int main()
{
#if DEBUG_IO
freopen("input.txt", "r", stdin);
setbuf(stdout, NULL);
#endif
int N;
scanf("%d", &N);
int i, j, k;
Node monkey[MAX];
int out[MAX + MAX];
int out_index = 0;
int count = 0;
int leave = 0;
while (true)
{
if(N == 0)
break;
int command = 0;
scanf("%d", &command);
if(command == ADD_ONE)
{
scanf("%d",&monkey[count].x);
scanf("%d",&monkey[count].age);
count++;
leave++;
}
else if(command == DEL_OLD)
{
if(leave == 0)
{
out[out_index++] = 0;
//printf("%d ", leave);
}
else
{
int temp = 0;
int oldest = 0;
for(i = 0; i < count; i++)
{
if(temp <= monkey[i].age && monkey[i].age != INF && monkey[i].age != 0)
{
temp = monkey[i].age;
oldest = i;
}
}
leave--;
monkey[oldest].age = INF;
out[out_index++] = monkey[oldest].x;
//printf("%d ", monkey[oldest].x);
}
}
else if(command == DEL_YOU)
{
if(leave == 0)
{
out[out_index++] = 0;
}
else
{
int temp = INF;
int youest = 0;
for(i = 0; i < count; i++)
{
if(temp >= monkey[i].age && monkey[i].age != INF && monkey[i].age != 0)
{
temp = monkey[i].age;
youest = i;
}
}
leave--;
monkey[youest].age = 0;
out[out_index++] = monkey[youest].x;
//printf("%d ", monkey[youest].x);
}
}
else if(command == IS_OVER)
{
break;
}
}
printf("%d", out[0]);
for(i = 1; i < out_index; i++)
{
printf(" %d", out[i]);
}
printf("\n");
for(i = 0; i < N; i++)
{
if(monkey[i].age != 0 && monkey[i].age != INF)
{
printf("%d", monkey[i].x);
break;
}
}
return 0;
}
/**************************************************************
Problem: 1026
User: xxxxxxxx
Language: C++
Result: 正确
Time:10 ms
Memory:304 kb
****************************************************************/
1026
最新推荐文章于 2022-04-29 09:38:03 发布