貪欲な話題 - 映画祭

例として映画祭

すべてのフィルムは間隔を上映している、重複の間隔は(エンドポイントが一致していてもよい)、同時に映画を見ることができない、あなたがするまで見ることができますどのように多くの映画尋ね
:入力した
n(nはフィールド<= 100)は、
(行ごとに2つの整数n行が続きます<1000)の間隔が表す表示さ
:出力
の最大数を

例:
入力
3
1 3
3 4
0 7
すべての小から大へのムービーサイズの終了に応じて、その後、映画、および各ステップを選択して、最後のステップは、ムービーを選択し、競合し、最早終了時刻ないことを最初の終わりを選択するための最初のステップフィルムは、
最も早い時刻を終了> -存在のためである
最前列の1-4 2-3は不正確になります:開始時間によってソートすることはできません。

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#define M  100010
#define INF 0x3f3f3f3f
const double EPS = 1e-6;
using namespace std;
struct movie{
    int begin,end;
    bool operator < (const movie &other)const{
        return end < other.end;
    }
}a[M];
int main(){
    int n;
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> a[i].begin >> a[i].end;
    sort(a,a+n);
    for(int i=0; i<n; i++)
        cout <<  a[i].begin << " " <<  a[i].end << endl;
    int now=0,cnt=0;
    for(int i=0; i<n; i++){
        if(a[i].begin>=now){
            now = a[i].end;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

公開された62元の記事 ウォンの賞賛0 ビュー1745

おすすめ

転載: blog.csdn.net/jhckii/article/details/104445480
おすすめ