The two questionsCodeBasically the same as PKU 3636
The main difference is that the second element is also sorted in ascending order. Because the first element is the same, the second element can be added in ascending order without adding a bucket again.
Therefore, an equal sign must be removed from the next judgment condition.
Pku1065
# Include <iostream> # include <algorithm> using namespace STD; struct node {int H, W; bool operator <(node A) {if (. W = W) return H <. h; return W <. W ;}} ele [5010]; int A [5010]; int main () {int cas, N; CIN> CAS; while (CAS --) {CIN> N; For (INT I = 0; I <n; I ++) CIN> ele [I]. w> ele [I]. h; sort (Ele, ELE + n); int q = 0; For (INT I = 0; I <n; I ++) {int L = 0, R = Q; while (L <r) {int M = (R + l)/2; if (a [m]> ele [I]. h) L = m + 1; else r = m;} A [l] = E Le [I]. h; // A [] Save the boundary value of each bucket q + = L = Q; // if no bucket is found, add a new bucket. } Cout <q <Endl;} return 0 ;}
PKU 1548
#include
#include
using namespace STD; struct node {int X, Y; friend bool operator <(const node & A, const node & B) {if (. X = B. x) return. Y
A> B & (! =-1 | B! =-1) {if (a = 0 & B = 0) {sort (Ele, ELE + n); int L, R, Q = 0; for (INT I = 0; I
ele [I]. y) L = m + 1; else r = m;} f [l] = ele [I]. y; q + = L = Q ;}cout