ICPC Live : 4493 (That is Your Queue)



// http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4493
// Cpu Time : 0.033s
// Memory : minimum 
// Algo : Ad-hoc


// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#define INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL unsigned long long
using namespace std;


int main ()
{
    int p, c;
    int cases = 0;

    while ( scanf ("%d %d", &p, &c) ) {
        if ( p == 0 && c == 0 ) break;

        list <int> l;

        p = min (c, p);

        for ( int i = 1; i <= p; i++ ) l.push_back (i);

        char ch [10];
        printf ("Case %d:\n", ++cases);

        for ( int i = 0; i < c; i++ ) {
            scanf ("%s", ch);
            if ( ch [0] == 'N' ) {
                printf ("%d\n", l.front ());
                l.push_back (l.front ());
                l.pop_front ();
            }
            else {
                int num;
                scanf ("%d", &num);
                l.remove (num);
                l.push_front (num);
            }
        }
    }

	return 0;
}

// @END_OF_SOURCE_CODE

One thought on “ICPC Live : 4493 (That is Your Queue)

  1. Critical input : 
    1000000000 13
    E 1000000000
    E 3
    E 2
    E 1000000000
    N
    N
    N
    N
    N
    N
    N
    N
    N
    0 0
    Output : 
    Case 1:
    1000000000
    2
    3
    1
    4
    5
    6
    7
    8
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s