luogu P2073 送花

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了luogu P2073 送花相关的知识,希望对你有一定的参考价值。

二次联通门 : luogu P2073 送花

 

 

 

/*
    luogu P2073 送花 

    ...
    机房里有写平衡树的
    有些线段树的
    
    大家都这么厉害
    
    那我就写个更厉害的吧..
    
    set大法好!!
    233333 
    
    注意一下set的begin()与end()是左闭右开的..被坑了一次 
*/
#include <cstdio>
#include <set>

void read (int &now)
{
    now = 0;
    char word = getchar ();
    bool flag = false;
    while (word > 9 || word < 0)
    {
        if (word == -)
            flag = true;
        word = getchar ();
    }
    while (word >= 0 && word <= 9)
    {
        now = now * 10 + word - 0;
        word = getchar ();
    }
    if (flag)
        now = -now;
}

struct Flower_Date
{
    int Value;
    int Cost;
    
    bool operator < (const Flower_Date &a) const
    {
        return a.Cost < this->Cost; 
    }
};

std :: set <Flower_Date> Make;

Flower_Date now;

int main (int argc, char *argv[])
{
    int Answer = 0, __Answer = 0;
    for (int type, x, y; ; )
    {
        read (type);
        if (type == -1)
        {
            for (std :: set <Flower_Date> :: iterator i = Make.begin (); i != Make.end (); i++)
            {
                Answer += (*i).Value;
                __Answer += (*i).Cost;
            }
            printf ("%d %d", Answer, __Answer);
            return 0;
        }
        if (type == 1)
        {
            read (now.Value);
            read (now.Cost);
            Make.insert (now);
        }
        else if (type == 2 && !Make.empty ())
        {
            now = *Make.begin ();
            Make.erase (now);
        }
        else if (type == 3 && !Make.empty ())
        {
            std :: set <Flower_Date> :: iterator Iter = Make.end ();
            Iter--;
            now = *Iter;
            Make.erase (now); 
        }
    }
    return 0;
}

 

以上是关于luogu P2073 送花的主要内容,如果未能解决你的问题,请参考以下文章

P2073 送花

洛谷 P2073 送花

P2073 送花

洛谷P2073 送花 [2017年6月计划 线段树01]

[Luogu] 送花

Luogu2073 送花 (平衡树)