标签:
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 21899 | Accepted: 9350 |
Description
Input
Output
Sample Input
3 5 4 9 5 2 2 1 3 5 1 4 3 2 2 1 1 2 2 3 1 3 2 2 3 1
Sample Output
2 1 3
Source
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
struct Node{
int x;
int y;
};
int cmp(Node a,Node b)
{
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
int main()
{
int t;
int n;
Node node[5005];
bool flag[5005]; //标志是否已经分组
while(cin>>t)
{
while(t--)
{
memset(flag,0,sizeof(flag));
cin>>n;
int ans=0;
for(int i=0;i<n;i++)
cin>>node[i].x>>node[i].y;
sort(node,node+n,cmp);
for(int i=0;i<n;i++)
{
if(flag[i]==0)
{
int p=node[i].y;
for(int j=i;j<n;j++)
{
if(flag[j]==0&&node[j].y>=p) {flag[j]=1;p=node[j].y;}
}
ans++;
}
}
cout<<ans<<endl;
}
}
}
整体思路就是,先按照长度对结构体排序,再进行遍历分组,如果满足p<y就满足分组条件,就修改标志位,这样遍历一遍,有ans个0,就有ans组,答案就是ans;
标签:
原文地址:http://www.cnblogs.com/hellohacker/p/5824137.html