【set】【HDU 5818】 Joint Stacks
2016-08-10 09:59
330 查看
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5818
题解:
http://bestcoder.hdu.edu.cn/blog/2016-multi-university-training-contest-7-solutions-by-sysu/
http://acm.hdu.edu.cn/showproblem.php?pid=5818
题解:
http://bestcoder.hdu.edu.cn/blog/2016-multi-university-training-contest-7-solutions-by-sysu/
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cstdlib> #include<set> #include<iterator> using namespace std; typedef struct point{ int x, y; bool operator < (const point& p) const{ return x > p.x; } bool operator >(const point& p) const{ return p < *this; } }p; char str[200], ins[100]; set<p> a, b, c; int main(){ //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int N; int Case = 0; while(~scanf("%d", &N) && N!=0){ getchar(); Case++; printf("Case #%d:\n", Case); a.clear(); b.clear(); c.clear(); char pos; int v; int num = 1; while(N--){ gets(str); if(str[1] == 'u'){ sscanf(str, "%s %c %d", ins, &pos, &v); p tmp; tmp.x = num, tmp.y = v; if(pos == 'A') a.insert(tmp); else b.insert(tmp); num++; } else if(str[1] == 'o'){ set<p>::iterator it; if(str[4] == 'A'){ if(a.size()!=0){ it = a.begin(); printf("%d\n", (*it).y); a.erase(it); } else{ it = c.begin(); printf("%d\n", (*it).y); c.erase(it); } } else{ if(b.size()!=0){ it = b.begin(); printf("%d\n", (*it).y); b.erase(it); } else{ it = c.begin(); printf("%d\n", (*it).y); c.erase(it); } } } else{ set<p>::iterator it; if(a.size()!=0){ for(it=a.begin(); it!=a.end(); it++){ p tmp = (*it); c.insert(tmp); } a.clear(); } if(b.size()!=0){ for(it=b.begin(); it!=b.end(); it++){ p tmp = (*it); c.insert(tmp); } b.clear(); } } } } return 0; }
相关文章推荐
- hdu 5818 Joint Stacks (模拟)
- hdu 5818 Joint Stacks(线段树)
- HDU-5818-Joint Stacks-模拟
- HDU 5818 Joint Stacks(左偏树)
- HDU 5818 Joint Stacks(栈)
- HDU 5818 多校第七场 1010 Joint Stacks (线段树)
- HDU 5818 Joint Stacks(其他)
- HDU 5818 Joint Stacks(左偏树)
- hdu 5818 Joint Stacks 2016 Multi-University 7
- HDU 5818 Joint Stacks [栈]【模拟】
- hdu 5818 Joint Stacks 栈
- hdu-5818 Joint Stacks(模拟)
- hdu 5818 Joint Stacks (优先队列)
- HDU 5818 Joint Stacks
- HDU 5818 Joint Stacks (优先队列、链表)
- 2016多校7 HDU 5818 Joint Stacks
- hdu 5818 Joint Stacks 优先队列(多校)
- HDU 5818 Joint Stacks
- HDU 5818 Joint Stacks 模拟
- HDU 5818 Joint Stacks 栈模拟