/****************************************************************************************************
A了一年多才过。。。离散化里面非常阴险的一种情况,就是给定一个区间[a, b]那么你放进arr数组中的应该是几个数呢?
很多人都以为是两个数a和b,实际上应该是四个数a, b, a - 1, b + 1,因为要考虑没处理的空间。。。够阴险吧~
****************************************************************************************************/
#include <iostream>
#include <functional>
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include <utility>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
#define LOWBIT(x) ( (x) & ( (x) ^ ( (x) - 1 ) ) )
#define CLR(x, k) memset((x), (k), sizeof(x))
#define CPY(t, s) memcpy((t), (s), sizeof(s))
#define SC(t, s) static_cast<t>(s)
#define LEN(s) static_cast<int>( strlen((s)) )
#define SZ(s) static_cast<int>( (s).size() )
typedef double LF;
//typedef long long LL; //GNU C++
//typedef unsigned long long ULL;
typedef __int64 LL; //Visual C++ 2010
typedef unsigned __int64 ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef map<int, int>::iterator MI;
typedef vector<int>::iterator VI;
typedef list<int>::iterator LI;
typedef set<int>::iterator SI;
template <typename T>
T sqa(const T &x)
{
return x * x;
}
template <typename T>
T gcd(T a, T b)
{
if (!a || !b)
{
return max(a, b);
}
T t;
while (t = a % b)
{
a = b;
b = t;
}
return b;
}
template <typename T>
T ext_gcd(T a, T b, T &x, T &y)
{
if (!b)
{
x = 1;
y = 0;
return a;
}
T d = ext_gcd(b, a % b, x, y);
T t = x;
x = y;
y = t - a / b * y;
return d;
}
template <typename T>
T invmod(T a, T p)
{
LL inv, y;
ext_gcd(a, p, inv, y);
inv < 0 ? inv += p : 0;
return inv;
}
const int INF_INT = 0x3f3f3f3f;
const LL INF_LL = 0x7fffffffffffffffLL; //15f
const double oo = 10e9;
const double eps = 10e-7;
const double PI = acos(-1.0);
const int MAXN = 4004 << 2;
int n, arr[MAXN];
int ncnt;
bool dp[MAXN];
struct Node
{
int l, r;
bool col;
}node[MAXN];
int bisearch(int x, int l, int r)
{
int mid = (l + r) >> 1, res = mid;
while (l <= r)
{
mid = (l + r) >> 1;
if (x == arr[mid])
{
res = mid;
break ;
}
if (x < arr[mid])
{
r = mid - 1;
}
else
{
l = mid + 1;
}
}
return res;
}
void ace()
{
char ch[2];
int x, y, maxi;
while (cin >> n)
{
CLR(dp, true);
for (int i = 0; i < n; ++i)
{
cin >> node[i].l >> node[i].r >> ch;
if ('w' == ch[0])
{
node[i].col = false;
}
else
{
node[i].col = true;
}
if (node[i].l > node[i].r)
{
swap(node[i].l, node[i].r);
}
arr[i * 4] = node[i].l - 1;
arr[i * 4 + 1] = node[i].l;
arr[i * 4 + 2] = node[i].r;
arr[i * 4 + 3] = node[i].r + 1;
}
sort(arr, arr + 4 * n);
ncnt = unique_copy(arr, arr + 4 * n, arr) - arr;
for (int i = 0; i < n; ++i)
{
int l = bisearch(node[i].l, 0, ncnt - 1);
int r = bisearch(node[i].r, 0, ncnt - 1);
for (int j = l; j <= r; ++j)
{
dp[j] = node[i].col;
}
}
int ind = 0;
while (ind < ncnt && dp[ind])
{
++ind;
}
if (ind == ncnt)
{
puts("Oh, my god");
continue ;
}
maxi = 0;
while (ind < ncnt)
{
int ptr = ind;
while (ptr < ncnt && !dp[ptr])
{
++ptr;
}
bool sign = false;
if (ptr >= ncnt)
{
sign = true;
}
--ptr;
int buf = (arr[ptr] - arr[ind] + 1);
if (buf > maxi)
{
x = arr[ind];
y = arr[ptr];
maxi = buf;
}
if (sign)
{
break ;
}
ind = ptr + 1;
while (dp[ind] && ind < ncnt)
{
++ind;
}
if (ind >= ncnt)
{
break ;
}
}
printf("%d %d\n", x, y);
}
return ;
}
int main()
{
ace();
return 0;
}
HDU 1199 离散化 很阴险
最新推荐文章于 2019-09-21 03:12:55 发布