问题 B: 【贪心】电视节目安排

it2022-05-09  40

有一种隐忍其实是蕴藏着的一种力量,有一种静默其实是惊天的告白。

题目描述

李旭琳发现小墨老师在班上是最顽劣的学生(没有之一),但他也有安静的时候,例如在看电视的时候。像什么“谍战剧”啊,“翻拍剧”啊,“婆媳戏”啊,“后宫剧”啊都是他的最爱。他甚至会事先查询所有喜欢看的电视节目的转播时间表并煞有介事的用红蓝铅笔列出计划,然后合理安排,以看到尽量多的完整节目。

 

输入

输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(n≤100),表示喜欢看的节目的总数,然后是n行数据,每行包括两个数据Ti_s,Ti_e (1≤i≤n),分别表示第i个节目的开始和结束时间,为了简化问题,每个时间都用一个正整数表示。n=0表示输入结束,不做处理。

 

输出

对于每个测试实例,输出能完整看到的电视节目的个数,每个测试实例的输出占一行。

 

样例输入

复制样例数据

12 1 3 3 4 0 7 3 8 15 19 15 20 10 15 8 18 6 12 5 10 4 14 2 9 0

样例输出

5 #include <map> #include <set> #include <list> #include <cmath> #include <deque> #include <queue> #include <stack> #include <cctype> #include <cstdio> #include <bitset> #include <string> #include <vector> #include <complex> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #include <functional> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; struct node { int ks; int js; }p[110]; int cmp(node x,node y){ if(x.js==y.js) return x.ks<y.ks; return x.js<y.js; } int main(){ int n,i; while(~scanf("%d",&n)&&n!=0){ int ct=1,j=0; for(i=0;i<n;i++) scanf("%d%d",&p[i].ks,&p[i].js); sort(p,p+n,cmp); for(i=1;i<n;i++){ if(p[i].ks>=p[j].js){ ct++; j=i; } } printf("%d\n",ct); } return 0; }

 


最新回复(0)