[cpp] /* 題目大意:將木棍分堆,保證每堆木頭的長度和重量都是非遞減的,最少分幾堆 * 解題思路:將木頭按長度非遞減排序,然後從第一個開始將重量能組成非遞減的木棍分堆即可 */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define MAX 10002 struct node { int x, y; } a[MAX]; bool cmp(node a, node b) { if( a.x == b.x ) return a.y < b.y; return a.x < b.x; } int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("test.in", "r", stdin); #endif int cnt, ans, n; scanf("%d", &cnt); for(int k = 0; k < cnt; k ++) { ans = 0; scanf("%d", &n); for(int i = 0; i < n; i ++) scanf("%d %d", &a[i].x, &a[i].y); sort(a, a + n, cmp); www.2cto.com for(int i = 0; i < n; i ++) { if( !a[i].x && !a[i].y ) continue ; for(int j = i + 1; j < n; j ++) { if( a[i].y <= a[j].y ) { a[i].x = a[j].x; a[i].y = a[j].y; a[j].x = a[j].y = 0; } } ans ++; } printf("%d\n", ans); } return 0; }