您的位置:首页 > 其它

51nod 1133 不重叠的线段

2017-07-27 20:17 204 查看
传送门---不重叠的线段

贪心--好像和一个看电视节目的是一个题

#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
struct node
{
int x,y;
};
bool cmp (node a,node b)
{
return a.y<b.y;
}
int main()
{  struct node t[10001];
int n;
while(cin>>n)
{ for(int i=0;i<n;i++)
scanf("%d %d",&t[i].x,&t[i].y);
sort(t,t+n,cmp);
int ans=1;
int tmp=t[0].y;
for(int i=1;i<n;i++)
{
if(t[i].x>=tmp)
{
ans++;
tmp=t[i].y;
}
}
cout<<ans<<endl;
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: