luogu P1803 线段覆盖 贪心

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 struct test
 5 {
 6     int a;
 7     int b;
 8     friend bool operator < (test x,test y)
 9     {
10         return x.b < y.b;
11     }
12 };
13 test vec[110000];
14 int main()
15 {
16     int n,last,res = 0;
17     cin >> n;
18     for (int i = 1;i <= n;i++)
19         cin >> vec[i].a >> vec[i].b;
20     sort(vec + 1,vec + n + 1);
21     last = 0;
22     for (int i = 1;i <= n;i++)
23     {
24         if (vec[i].a >= last)
25         {
26             last = vec[i].b;
27             res++;
28         }
29     }
30     cout << res << endl;
31     return 0;
32 }

猜你喜欢

转载自www.cnblogs.com/iat14/p/11234320.html
今日推荐