首页 > 代码库 > luogu P2073 送花
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 送花
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。