标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32877 Accepted Submission(s): 17471
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <iostream> #include <string> #include <algorithm> using namespace std; struct node { int st; //起始时间 int et; //结束时间 bool operator <(const node &x)const{ if(et==x.et) return st<x.st; else return et<x.et; } }q[200]; int main() { int n; int i, j; while(scanf("%d", &n) && n!=0 ) { for(i=0; i<n; i++) { scanf("%d %d", &q[i].st, &q[i].et ); } sort(q, q+n); int ans=1; int j=0; //第一个最早结束的节目必然要被选中 for(i=1; i<n; i++) { if(q[i].st >= q[j].et ) { ans++; j=i; //更新到当前刚选中节目的下标 } } printf("%dn", ans ); } return 0; }
HDU 2037 今年暑假不AC ( 起始与终止时间 【贪心】)
标签:
原文地址:http://www.cnblogs.com/yspworld/p/4385441.html