AC代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; #define Max 5005 struct wooden { int l; int w; int sign; }wood[Max]; //定义1个结构体数组 bool compare(wooden a, wooden b) { if(a.l == b.l ) return a.w < b.w; else return a.l < b.l; } int main(void) { freopen("in.txt","r",stdin); int N; //定义第一个n scanf("%d",&N); while(N--) { int n; //定义第二个n scanf("%d",&n); int count = 0, l0, w0; //定义count变量用来记录需要多少minutes,l0,w0是机器的初始化 for(int i = 1; i <= n; i++) //输入 { scanf("%d%d", &wood[i].l, &wood[i].w); } for(int i = 1; i <= n; i++) wood[i].sign = 0; //让游标都为0 sort(wood + 1, wood + n + 1, compare); //进行排序处理 for(int j=1; j<=n; j++) if(wood[j].sign == 0) { count++; l0 = wood[j].l; w0 = wood[j].w; wood[j].sign = 1; for(int i = j+1; i <= n ; i++) { if(wood[i].sign == 0) { if(l0 <= wood[i].l && w0 <= wood[i].w) { l0 = wood[i].l; w0 = wood[i].w; wood[i].sign = 1; } } } } printf("%d ",count); } fclose(stdin); system("pause"); return 0; }