九度笔记之 1463:招聘会

题目1463:招聘会

时间限制:1 秒

内存限制:128 兆

特殊判题:

提交:306

解决:91

题目描述:

又到毕业季,很多大公司来学校招聘,招聘会分散在不同时间段,小明想知道自己最多能完整的参加多少个招聘会(参加一个招聘会的时候不能中断或离开)。

输入:

第一行n,有n个招聘会,接下来n行每行两个整数表示起止时间,由从招聘会第一天0点开始的小时数表示。
n <= 1000 。

输出:

最多参加的招聘会个数。

样例输入:
3
9 10
10 20
8 15
样例输出:
2

算法分析

       参见 题目1434:今年暑假不AC




源程序

//============================================================================
// Name        : judo1434.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
  
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
struct TVshow{
    int begt;
    int endt;
};
std::vector<TVshow> tvs;
bool lessthan(const TVshow & tsl,const TVshow &tsr){
    return tsl.endt < tsr.endt;
}
void noAC(int n){
    TVshow ts;
    tvs.clear();
    for(int i = 0;i<n;i++){
        std::cin>>ts.begt>>ts.endt;
        tvs.push_back(ts);
    }
    std::sort(tvs.begin(),tvs.end(),lessthan);
  
    int endtime = tvs.back().endt;
    int *maxn = new int[endtime+1];
  
    for(int i = 0;i<endtime+1;i++)
        maxn[i]=0;
  
    for(int i = 0;i<n;i++){
        int temMaxn = std::max(maxn[tvs.at(i).endt],maxn[tvs.at(i).begt]+1);
        for(int j = tvs.at(i).endt; j<endtime+1; j++){
            //maxn[j] = temMaxn;
            maxn[j] = std::max(maxn[j],temMaxn);
        }
    }
    std::cout<<maxn[endtime]<<std::endl;
}
int main() {
    //cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    int n;
    while(std::cin>>n && n!=0){
        noAC(n);
    }
    return 0;
}
/**************************************************************
    Problem: 1463
    User: KES
    Language: C++
    Result: Accepted
    Time:10 ms
    Memory:1520 kb
****************************************************************/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值