题解 | 活动安排
活动安排
https://www.nowcoder.com/practice/16d971e9e42e4f3b9b1e2b8794796a43
#include <stdio.h> #include <stdlib.h> struct st{ long long a; long long b; }; int com(const void *a,const void *b) { struct st * aa = (struct st *)a; struct st * bb = (struct st *)b; return aa->b - bb->b; } int main() { int i,j=0, n, tmp, num=0, t=1; scanf("%d",&n); struct st *nu = (struct st *)malloc(sizeof(struct st) * n); for(int i=0;i<n;i++) { scanf("%lld %lld",&nu[i].a,&nu[i].b); } qsort(nu, n, sizeof(struct st), com); i=0; while(i<n-1) { j=i+1; while(nu[j].a < nu[i].b && j<n) { j++; } if(j<n) { t++; i=j; } else { break; } } printf("%d\n",t); return 0; }