hdu 1051Wooden Sticks

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define maxn 10000
 5 using namespace std;
 6 struct node
 7 {
 8     int s,e;
 9     bool operator <(const node &a)const
10     {
11         return (s<a.s||(s==a.s&&e<a.e));
12     }
13 }p[maxn];
14 bool vis[maxn];
15 int main()
16 {
17     int t,n;
18     scanf("%d",&t);
19     while(t--)
20     {
21         memset(vis,false,sizeof(vis));
22         scanf("%d",&n);
23         for(int i=0; i<n; i++)
24         {
25             scanf("%d%d",&p[i].s,&p[i].e);
26         }
27         sort(p,p+n);
28         int num=0,end;
29         for(int i=0; i<n; i++)
30         {
31             if(!vis[i])
32             {
33                 num++;
34                 end=p[i].e;
35                 vis[i]=true;
36                 for(int j=i+1; j<n; j++)
37                 {
38                     if(!vis[j]&&p[j].e>=end)
39                     {
40                         end=p[j].e;
41                         vis[j]=true;
42                     }
43                 }
44             }
45         }
46         printf("%d
",num);
47     }
48     return 0;
49 }
View Code
原文地址:https://www.cnblogs.com/fanminghui/p/3531813.html