终于想通了,坑爹的,谁跟我说要dp呢,贪心就能解决嘛,哈哈~ #include <cstdio> #include <algorithm> using namespace std; struct tv{ int s,e; }t[101]; bool cmp(tv a,tv b){ return (a.e-b.e)<0; } int main(){ int n; while(scanf("%d",&n)&&n!=0){ for(int i=0;i<n;i++){ scanf("%d%d",&t[i].s,&t[i].e); } sort(t,t+n,cmp);//按照结束时间升序排序 int res=0,end=t[0].s; for(int i=0;i<n;i++){ if(t[i].s>=end){ res++; end=t[i].e; } } printf("%d\n",res); } return 0; }