cf(M) Manhattan Mornings
Posted yeah17981
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cf(M) Manhattan Mornings相关的知识,希望对你有一定的参考价值。
Dashboard - 2017 Benelux Algorithm Programming Contest (BAPC 17) - Codeforces
上篇博客前言+1
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
const int N = 100010;
pii p[N];
int cnt;
int dp[N], len;
bool cmp1(pii& p1, pii& p2)
{
if(p1.first != p2.first) return p1.first < p2.first;
else return p1.second < p2.second;
}
bool cmp2(pii& p1, pii& p2)
{
if(p1.second != p2.second) return p1.second < p2.second;
else return p1.first < p2.first;
}
bool cmp3(pii& p1, pii& p2)
{
if(p1.first != p2.first) return p1.first < p2.first;
else return p1.second > p2.second;
}
bool cmp4(pii& p1, pii& p2)
{
if(p1.second != p2.second) return p1.second < p2.second;
else return p1.first > p2.first;
}
int main()
{
int n;
int x1, y1, x2, y2;
cin >> n >> x1 >> y1 >> x2 >> y2;
if(x2 < x1) swap(y1, y2), swap(x1, x2);
for(int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
if(x < min(x1, x2) || x > max(x1, x2) || y < min(y1, y2) || y > max(y1, y2)) continue;
p[cnt++] = {x, y};
}
int res = 0;
if(y1 <= y2)
{
len = 0;
sort(p, p + cnt, cmp1);
for(int i = 0; i < cnt; i++)
{
int l = 0, r = len;
while(l < r)
{
int mid = l + r >> 1;
if(dp[mid] <= p[i].second) l = mid + 1;
else r = mid;
}
dp[l] = p[i].second;
if(l == len) len++;
}
res = max(res, len);
len = 0;
sort(p, p + cnt, cmp2);
for(int i = 0; i < cnt; i++)
{
int l = 0, r = len;
while(l < r)
{
int mid = l + r >> 1;
if(dp[mid] <= p[i].first) l = mid + 1;
else r = mid;
}
dp[l] = p[i].first;
if(l == len) len++;
}
res = max(res, len);
}
else
{
sort(p, p + cnt, cmp3);
len = 0;
for(int i = 0; i < cnt; i++)
{
int l = 0, r = len;
while(l < r)
{
int mid = l + r >> 1;
if(dp[mid] >= p[i].second) l = mid + 1;
else r = mid;
}
dp[l] = p[i].second;
if(l == len) len++;
}
res = max(res, len);
len = 0;
sort(p, p + cnt, cmp4);
for(int i = 0; i < cnt; i++)
{
int l = 0, r = len;
while(l < r)
{
int mid = l + r >> 1;
if(dp[mid] >= p[i].first) l = mid + 1;
else r = mid;
}
dp[l] = p[i].first;
if(l == len) len++;
}
res = max(res, len);
}
cout << res << endl;
}
以上是关于cf(M) Manhattan Mornings的主要内容,如果未能解决你的问题,请参考以下文章