1323:活動の選択

 

説明[タイトル]

最近では学校が持っているn個

学校の講堂の使用を必要とする2つの活動が、同時に、講堂は活動のみで使用することができます。いくつかのアクティブ時間の競合があるので、学校の事務職員は、いくつかの活動や他の教室のためのホールの使用を断念しなければなりませんでした。

今与えられたn個

ホールの活性な出発時刻用いB E G I N- I及び終了時間E N- D IB E G I N- I < E N- D Iを

できるだけスケジュールされたイベントを必要とし、会場を使用するアクティビティの数を手配するために、あなたのオフィスのスタッフを助けてください。

[Enter]を

整数最初の行N-N- ≤1000)

;

のn

二つの整数、最初のラインB E G I N- I、第二はE N- D IB E G I N- I < E N- D I ≤32767)

[出力]

スケジュールされたアクティビティの数に出力アップ。

[サンプル入力】

11
3 5
1 4
12 14
8 12
0 6
8 11
6 10
5 7
3 8
5 9
2 13

[サンプル出力]

4
// Created on 2020/2/11

/*#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <climits>*/
#include <bits/stdc++.h>

using namespace std;

const int idata=10000+5;
int begins[idata];
int End[idata];
int n,m;
int flag;
int cnt;
int maxx=0;
pair<int ,int> thep[idata];
int x,y;

int main()
{
    int i,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x>>y;
        begins[i]=x;
        End[i]=y;
    }

    for(i=1;i<=n;i++)
    {
        thep[i].first=End[i];
        thep[i].second=begins[i];
    }
    sort(thep+1,thep+n+1);//对first从小到大排序

    for(i=1;i<=n;i++)
    {
        if(m<=thep[i].second)//两活动之间可以无缝衔接
        {
            m=thep[i].first;
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

 ペアのソートブログを添付:

 

https://blog.csdn.net/qian2213762498/article/details/81773289 

公開された177元の記事 ウォンの賞賛8 ビュー6336

おすすめ

転載: blog.csdn.net/C_Dreamy/article/details/104283040