HDU : 1707 (Spring-outing Decision)


// http://acm.hdu.edu.cn/showproblem.php?pid=1707

// @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 <utility>
#include <set>
#include <math.h>
#define pi acos(-1.0)
#define N 1000000
using namespace std;

struct info {
    string name;
    bool busy [7 + 2] [11 + 2];
} a [200 + 5];

void reset (int s)
{
    for ( int i = 0; i <= s; i++ ) {
        a [i].name = "";
        for ( int j = 0; j < 9; j++ ) {
            for ( int k = 0; k < 13; k++ )
                a [i].busy [j] [k] = false;
        }
    }
}

bool cmp (info p, info q)
{
    if ( p.name < q.name )
        return true;
    return false;
}

int main ()
{
    int testCase;
    scanf ("%d", &testCase);

    while ( testCase-- ) {
        int student;
        scanf ("%d", &student);

        reset (student);

        for ( int i = 0; i < student; i++ ) {
            int course;
            cin >> a [i].name >> course;

            for ( int j = 0; j < course; j++ ) {
                int d, s, e;
                scanf ("%d %d %d", &d, &s, &e);
                for ( int k = s; k <= e; k++ )
                    a [i].busy [d] [k] = true;
            }
        }

        sort (a, a + student, cmp);

        int query;
        scanf ("%d", &query);
        vector <string> output;

        for ( int i = 0; i < query; i++ ) {
            output.clear ();
            int d, s, e;
            scanf ("%d %d %d", &d, &s, &e);
            for ( int j = 0; j < student; j++ ) {
                for ( int k = s; k <= e; k++ ) {
                    if ( a [j].busy [d] [k] ) {
                        output.push_back (a [j].name);
                        break;
                    }
                }
            }

            if ( output.size () == 0 )
                printf ("None\n");
            else {
                cout << output [0];
                for ( size_t i = 1; i < output.size (); i++ )
                    cout << " " << output [i];
                cout << endl;
            }
        }
    }

    return 0;
}

// @END_OF_SOURCE_CODE

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