HDU : 2600 (War)


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

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

struct year {
    int start;
    int end;
} a [100 + 5];

bool cmp (year x, year y)
{
    if ( x.start <= y.start ) return true;
    return false;
}

int main ()
{
    int n;

    while ( scanf ("%d", &n) != EOF ) {
        int startRange;
        int endRange;
        scanf ("%d %d", &startRange, &endRange);

        for ( int i = 0; i < n; i++ ) {
            char faul [1000];
            cin >> a [i].start >> a [i].end;
            gets (faul);
        }

        sort (a, a + n, cmp);

        int output = (N * 10 * -1); // not set (garbage value)
        int s = a [0].start;
        int e = a [0].end;

        for ( int i = 1; i < n; i++ ) {
            if ( a [i].start > e + 1  ) {
                output = a [i].start - 1;
                s = a [i].start;
                e = a [i].end;
            }
            else if ( a [i].start <= e + 1 ) {
                e = a [i].end;
            }
        }

        if ( e < endRange )
            output = endRange;

        if ( output == (N * 10 * -1)) printf ("Badly!\n");
        else printf ("%d\n", output);
    }

    return 0;
}

// @END_OF_SOURCE_CODE
Advertisements

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