题目链接:
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1133
题解:
用贪心的思想,把终点进行升序的操作以后,再按条件进行选择,满足条件的就加一下。
代码:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define met(a,b) memset(a,b,sizeof(a))
const int maxn = 1e4+10;
typedef long long ll;
struct node
{
ll x,y;
}s[maxn];
ll cmp(node a,node b)
{
return a.y<b.y;
}
int main()
{
ll n;
while(cin>>n)
{
for(ll i=0;i<n;i++)
cin>>s[i].x>>s[i].y;
sort(s,s+n,cmp);
ll cnt=1;
for(ll i=1;i<n;i++)
{
if(s[i].x>=s[0].y)
{
cnt++;
s[0].y=s[i].y;
}
}
cout<<cnt<<endl;
}
}