题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5818
题解:
http://bestcoder.hdu.edu.cn/blog/2016-multi-university-training-contest-7-solutions-by-sysu/
1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstring> 5 #include<cstdlib> 6 #include<set> 7 #include<iterator> 8 using namespace std; 9 typedef struct point{ 10 int x, y; 11 bool operator < (const point& p) const{ 12 return x > p.x; 13 } 14 bool operator >(const point& p) const{ 15 return p < *this; 16 } 17 }p; 18 19 char str[200], ins[100]; 20 set<p> a, b, c; 21 22 int main(){ 23 //freopen("in.txt", "r", stdin); 24 //freopen("out.txt", "w", stdout); 25 int N; 26 int Case = 0; 27 while(~scanf("%d", &N) && N!=0){ 28 getchar(); 29 Case++; 30 printf("Case #%d:\n", Case); 31 a.clear(); 32 b.clear(); 33 c.clear(); 34 char pos; 35 int v; 36 int num = 1; 37 while(N--){ 38 gets(str); 39 if(str[1] == 'u'){ 40 sscanf(str, "%s %c %d", ins, &pos, &v); 41 p tmp; 42 tmp.x = num, tmp.y = v; 43 if(pos == 'A') a.insert(tmp); 44 else b.insert(tmp); 45 num++; 46 } 47 else if(str[1] == 'o'){ 48 set<p>::iterator it; 49 if(str[4] == 'A'){ 50 if(a.size()!=0){ 51 it = a.begin(); 52 printf("%d\n", (*it).y); 53 a.erase(it); 54 } 55 else{ 56 it = c.begin(); 57 printf("%d\n", (*it).y); 58 c.erase(it); 59 } 60 } 61 else{ 62 if(b.size()!=0){ 63 it = b.begin(); 64 printf("%d\n", (*it).y); 65 b.erase(it); 66 } 67 else{ 68 it = c.begin(); 69 printf("%d\n", (*it).y); 70 c.erase(it); 71 } 72 } 73 } 74 else{ 75 set<p>::iterator it; 76 if(a.size()!=0){ 77 for(it=a.begin(); it!=a.end(); it++){ 78 p tmp = (*it); 79 c.insert(tmp); 80 } 81 a.clear(); 82 } 83 if(b.size()!=0){ 84 for(it=b.begin(); it!=b.end(); it++){ 85 p tmp = (*it); 86 c.insert(tmp); 87 } 88 b.clear(); 89 } 90 } 91 } 92 } 93 94 return 0; 95 }