1. 程式人生 > >luogu2782友好城市

luogu2782友好城市

return 拒絕 tdi sca radius 有一個 AS 交叉 而且

題目描述

有一條橫貫東西的大河,河有筆直的南北兩岸,岸上各有位置各不相同的N個城市。北岸的每個城市有且僅有一個友好城市在南岸,而且不同城市的友好城市不相同。每對友好城市都向政府申請在河上開辟一條直線航道連接兩個城市,但是由於河上霧太大,政府決定避免任意兩條航道交叉,以避免事故。編程幫助政府做出一些批準和拒絕申請的決定,使得在保證任意兩條航道不相交的情況下,被批準的申請盡量多。

輸入輸出格式

輸入格式:

第1行,一個整數N,表示城市數。

第2行到第n+1行,每行兩個整數,中間用一個空格隔開,分別表示南岸和北岸的一對友好城市的坐標。

輸出格式:

僅一行,輸出一個整數,表示政府所能批準的最多申請數。

輸入輸出樣例

輸入樣例#1: 復制
7
22 4
2 6
10 3
15 12
9 8
17 17
4 2
輸出樣例#1: 復制
4

說明

50% 1<=N<=5000,0<=xi<=10000

100% 1<=N<=2e5,0<=xi<=1e6

#include<iostream>
#include<algorithm> 
#include<cstdio>
using namespace std;
#define X 300000+7
int a[X],f[X];
struct Node{
    int u,v;
}map[X];
bool pd(Node a,Node b) { return a.u<b.u; } int main() { int n; scanf("%d",&n); for(int i=1;i<=n;++i) { scanf("%d%d",&map[i].u,&map[i].v); } sort(map+1,map+1+n,pd); int len=1;f[1]=map[1].v; for(int i=2;i<=n;++i) { if(map[i].v>f[len])f[++len]=map[i].v;
else { int j=upper_bound(f+1,f+1+len,map[i].v)-f;f[j]=map[i].v; } } cout<<len; }

luogu2782友好城市