zoukankan      html  css  js  c++  java
  • 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
    ",top);
    54 }
    View Code
  • 相关阅读:
    MFC 解析xml文件
    数字图像处理-----主成成分分析PCA
    C++设计模式——建造者模式
    总结的文章--未读
    八大排序算法
    C++读取、旋转和保存bmp图像文件编程实现
    数字图像处理-----直方图均衡化
    数字图像处理------中值滤波
    matlab图像基础知识
    MFC最大化显示任务栏
  • 原文地址:https://www.cnblogs.com/zhangchengbing/p/3307749.html
Copyright © 2011-2022 走看看