3
3
2016
0

[BZOJ1664] [Usaco2006 Open]County Fair Events 参加节日庆祝

排序直接做就行了

#include<cstdio>
#include<algorithm>
using namespace std;

int n,ans=0;

struct Event{
int s,t;
friend bool operator<(Event a,Event b){
return (a.t<b.t)||(a.t==b.t && a.s<b.s);
}
}e[10005];

int main(){
freopen("1664.in","r",stdin);
freopen("1664.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++){
	scanf("%d %d",&e[i].s,&e[i].t);
	e[i].t+=e[i].s;
}
sort(e+1,e+n+1);
int last=0;
for(int i=1;i<=n;i++){
	if(e[i].s>=e[last].t){
		ans++;
		last=i;
	}
	else if(e[i].t<e[last].t){
		last=i;
	}
}
printf("%d\n",ans);
return 0;
}
Category: BZOJ | Tags: OI bzoj | Read Count: 257

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com