ural 1203. Scientific Conference(动态规划)

本文探讨了如何在科学会议上合理安排报告时间,以确保参与者能够最大化地参与感兴趣的报告,同时考虑时间限制和报告间的间隔。通过算法实现,提高了会议效率和参与者的满意度。

1203. Scientific Conference

Time limit: 1.0 second Memory limit: 64 MB
Functioning of a scientific conference is usually divided into several simultaneous sections. For example, there may be a section on parallel computing, a section on visualization, a section on data compression, and so on.
Obviously, simultaneous work of several sections is necessary in order to reduce the time for scientific program of the conference and to have more time for the banquet, tea-drinking, and informal discussions. However, it is possible that interesting reports are given simultaneously at different sections.
A participant has written out the time-table of all the reports which are interesting for him. He asks you to determine the maximal number of reports he will be able to attend.

Input

The first line contains the number 1 ≤ N ≤ 100000 of interesting reports. Each of the next N lines contains two integers Ts and Te separated with a space (1 ≤ Ts < Te ≤ 30000). These numbers are the times a corresponding report starts and ends. Time is measured in minutes from the beginning of the conference.

Output

You should output the maximal number of reports which the participant can attend. The participant can attend no two reports simultaneously and any two reports he attends must be separated by at least one minute. For example, if a report ends at 15, the next report which can be attended must begin at 16 or later.

Sample

inputoutput
5
3 4
1 5
6 7
4 5
1 3
3

 

 1 #include <cstring>
 2 #include <cstdio>
 3 #include <string>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <cmath>
 7 using namespace std;
 8 struct node
 9 {
10     int x,y;
11 } p[100001];
12 int flag[100001];
13 int cmp(node a,node b)
14 {
15     if(a.x == b.x)
16         return a.y < b.y;
17     else
18         return a.x < b.x;
19 }
20 int main()
21 {
22     freopen("1.txt","r",stdin);
23     int n,i,j,ans,maxz,top;
24     scanf("%d",&n);
25     for(i =0; i < n; i ++)
26     {
27         scanf("%d%d",&p[i].x,&p[i].y);
28     }
29     memset(flag,-1,sizeof(flag));
30     sort(p,p+n,cmp);
31     ans=1;
32     flag[1] = p[0].y;
33     top = 1;
34     for(i =1;i<n;i++)
35     {
36         maxz = 0;
37         for(j=top;j>=1;j--)
38         {
39             if(p[i].x>flag[j])
40             {
41                 maxz=j;
42                 break;
43             }
44         }
45         if(flag[maxz+1]==-1)
46         {
47             flag[maxz+1] = p[i].y;
48             top ++;
49         }
50         else
51             flag[maxz+1] = min(flag[maxz+1],p[i].y);
52     }
53     printf("%d\n",top);
54 }
View Code

 

转载于:https://www.cnblogs.com/zhangchengbing/p/3307749.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值