P2782 Sister Cities

Questions surface: https://www.luogu.org/problemnew/show/P2782

This problem can be either the south bank of the North Shore as a key first from small to large, and then find the longest sequence to rise on the other shore.

Code:

#include<iostream>
#include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> #include<algorithm> #include<ctime> using namespace std; const int N=200005; int m,b[N],len,d[N]; struct Node{ int n,s; }a[N]; bool cmp(Node p,Node q){ if(p.n==q.n){ return p.s<q.s; } return p.n<q.n; } int main(){ scanf("%d",&m); for(int i=1;i<=m;i++){ scanf("%d%d",&a[i].n,&a[i].s); } sort(a+1,a+1+m,cmp); d[++len]=a[1].s; for(int i=2;i<=m;i++){ if(a[i].s>d[len]){ d[++len]=a[i].s; } else{ int j=upper_bound(d+1,d+1+len,a[i].s)-d; d[j]=a[i].s; } } printf("%d\n",len); return 0; } 

Guess you like

Origin www.cnblogs.com/ukcxrtjr/p/11119987.html