信息学奥赛一本通 1.1

信息学奥赛一本通 1.1

1.1.1 活动安排

传送门:活动安排

/*
problem:loj.ac 10000
date:2019/04/21
author:xiaoziyao
state:AC
*/
#include
using namespace std;
const int maxn=1005;
int i,j,k,m,n,ans,tmp;
struct act{
	int s,t;
}a[maxn];
int cmp(act x,act y){
	return x.t<y.t? 1:0;
}
void init(){
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d%d",&a[i].s,&a[i].t);
}
void solve(){
	sort(a+1,a+1+n,cmp);
	ans=1,tmp=a[1].t;
	for(i=2;i<=n;i++)
		if(a[i].s>=tmp)
			tmp=a[i].t,ans++;
}
void out(){
	printf("%d\n",ans);
}
int main(){
	init();
	solve();
	out();
	return 0;
}
/*
in:
4
1 3
4 6
2 5
1 7
out:
2
*/

1.1.2 种树

传送门:种树

/*
problem:loj.ac 10001
date:2019/04/21
author:xiaoziyao
state:AC
*/
#include
using namespace std;
const int maxn=30005,maxm=5005;
int i,j,k,m,n,ans,vis[maxn];
struct advise{
	int b,e,t;
}a[maxm];
int cmp(advise x,advise y){
	return x.e<y.e;
}
void init(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
		scanf("%d%d%d",&a[i].b,&a[i].e,&a[i].t);
}
void solve(){
	sort(a+1,a+1+m,cmp);
	for(i=1;i<=m;i++){
		int cnt=0;
		for(j=a[i].b;j<=a[i].e;j++)
			cnt+=vis[j];
		if(cnt>=a[i].t)
			continue;
		for(j=a[i].e;j>=a[i].b;j--)
			if(!vis[j]){
				vis[j]=1,cnt++,ans++;
				if(cnt==a[i].t)
					break;
			}
	}
}
void out(){
	printf("%d\n",ans);
}
int main(){
	init();
	solve();
	out();
	return 0;
}
/*
in:
9
4
1 4 2
4 6 2
8 9 2
3 5 2
out:
5
*/

你可能感兴趣的:(信息学奥赛一本通)