1026

#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 
****************************************************************/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值