二次联通门 : 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; }
时间: 2024-10-04 10:35:57