codeforces 597B Restaurant

题目链接:http://codeforces.com/contest/597/problem/B

题目分类:贪心

题目分析:经典的看节目问题(挑战程序设计page 40)

代码:

#include<bits/stdc++.h>

using namespace std;

struct P
{
int st,en;
}order[]; int cmp(P X,P Y)
{
return X.en<Y.en;
} int main()
{
int n;
scanf("%d",&n);
memset(order,,sizeof(order));
for(int i=;i<=n;i++)
{
cin>>order[i].st>>order[i].en;
} sort(order+,order+n+,cmp); int ans=,t=;
for(int i=;i<=n;i++)
{
if(order[i].st>t)
{
ans++;
t=order[i].en;
} }
printf("%d\n",ans);
return ;
}
上一篇:论文学习-深度学习目标检测2014至201901综述-Deep Learning for Generic Object Detection A Survey


下一篇:string用scanf读入printf输出(节省时间)