题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=236
注意使用标记。标记已经处理过的。
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct point{
int len,weight;
}a[5005];
bool cmp(point x,point y){////按照长度排序,如果长度相同则按重量排序
if(x.len<y.len)
return true;
if(x.len==y.len&&x.weight<y.weight)
return true;
return false;
}
int main(){
int ncase,n;
scanf("%d",&ncase);
while(ncase--){
memset(a,0,sizeof(a));
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d",&a[i].len,&a[i].weight);
sort(a,a+n,cmp);
int count=0;
for(int i=0;i<n;i++){
if(a[i].weight!=0){
int t=a[i].weight;
count++;
for(int j=i+1;j<n;j++){
if(a[j].weight>=t){
t=a[j].weight;
a[j].weight=0;
}
}
}
}
printf("%d\n",count);
}
}