8 solutions
-
2
题解
先将活动结束时间排序,再依次判断活动能否举办,注意cnt一开始要为1
代码
#include<bits/stdc++.h> using namespace std; struct sum{ int a,b; }suum[1005]; bool cmp(sum x,sum y){ return x.b<y.b; } int main() { int n,cnt=1,i=0,j=0; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d %d",&suum[i].a,&suum[i].b); } sort(suum,suum+n,cmp); for(i=1;i<n;i++) { if(suum[i].a>=suum[j].b) { j=i; cnt++; } } printf("%d",cnt); return 0; }
Information
- ID
- 91
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 201
- Accepted
- 61
- Uploaded By