zoukankan      html  css  js  c++  java
  • 凌乱的yyy

    题意

    安排比赛,且不能同时进行两个比赛,使比赛场数最多。


    分析

    这题用贪心的方法来做,先排序结束时间,再依次考虑各个活动。


    var
    n,i,tj,t:longint;
    a,b:array[0..1000000]of longint;


    procedure kp(l,r:longint);
    var
    i,j,mid:longint;
    begin
        if l>=r then exit;
        i:=l;j:=r;mid:=b[(l+r) div 2];
        repeat
             while b[i]<mid do inc(i);
             while b[j]>mid do dec(j);
             if i<=j then
             begin
                 a[0]:=a[i];a[i]:=a[j];a[j]:=a[0];
                 b[0]:=b[i];b[i]:=b[j];b[j]:=b[0];
                 inc(i);dec(j);
            end;
        until i>j;
        kp(l,j);
        kp(i,r);
    end;


    begin
        readln(n);
        for i:=1 to n do
        readln(a[i],b[i]);
        kp(1,n);
        tj:=0;
        t:=-1;
        for i:=1 to n do
        if a[i]>=t then
        begin
            t:=b[i];
            inc(tj);
        end;
        write(tj);
    end.

  • 相关阅读:
    codeforces 862B
    codeforces 863B
    codeforces 864B
    codeforces 867B
    codeforces 868B Race Against Time
    codeforces 869B The Eternal Immortality
    CodeForces
    nyoj 括号配对问题(模拟栈的过程)
    HDU
    nyoj 119 士兵杀敌(三)线段树
  • 原文地址:https://www.cnblogs.com/YYC-0304/p/9500211.html
Copyright © 2011-2022 走看看