First, we need to distinguish between qsort in # include <cstdlib> and sort in C ++ STL algorithm. The latter has only three parameters and the comparison function is easier to write.
Similar to poj 1065, there are two differences. One is that the sorting method drops, and the other is that the requirements fall and are not equal.
However, regular greedy requests will time out and will not time out after optimization by binary mode. Note that the L-incrementing and W-decimal rows
// Similar to poj 1065, there are two differences. One is that the sorting method drops, and the other is that the requirement drops and is not equal. <br/> // The above solution times out, do not time out after optimization with binary mode. Pay attention to the ascending l column, descending W rows <br/> # include <iostream> <br/> # include <cstdio> <br/> # include <cstdlib> <br/> using namespace STD; <br/> typedef struct stick {<br/> int L; <br/> int W; <br/>} Stick; <br/> int CMP (const void * a, const void * B) <br/> {<br/> If (* (stick *) ). l! = (* (Stick *) B ). l) <br/> {<br/> return (* (stick *) ). l-(* (stick *) B ). l; <br/>}< br/> else <br/> {<br/> return (* (stick *) B ). w-(* (stick *) ). w; <br/>}< br/> int main () {<br/> int n, m, I; <br/> int T [20010], Len = 0, R, L, mid; <br/> stick P [20005]; <br/> scanf ("% d", & N); <br/> while (n --) {<br/> Len = 0; <br/> scanf ("% d", & M); <br/> for (I = 0; I <m; I ++) <br/>{< br/> scanf ("% d", & P [I]. l, & P [I]. w); <br/>}< br/> qsort (p, M, sizeof (stick), CMP); <br/> memset (T, 0, sizeof (t); <br/> for (I = 0; I <m; I ++) <br/>{< br/> L = 0; <br/> r = Len; <br/> while (L <r) // uses binary optimization <br/> {<br/> mid = (L + r) /2; <br/> If (T [Mid]> = P [I]. w) L = Mid + 1; <br/> else r = mid; <br/>}< br/> If (LEN = L) Len ++; <br/> T [l] = P [I]. w; <br/>}< br/> printf ("% d/N", Len); <br/>}< br/> return 0; <br/>}< br/>