码迷,mamicode.com
首页 > 其他好文 > 详细

mutiset HDOJ 5349 MZL's simple problem

时间:2015-08-05 18:15:59      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

 1 /*
 2     这题可以用stl的mutiset容器方便求解,我对这东西不熟悉,TLE了几次,最后用读入外挂水过。
 3     题解有O(n)的做法,还以为我是侥幸过的,后来才知道iterator it写在循环内才超时了,囧!
 4 */
 5 /************************************************
 6 Author        :Running_Time
 7 Created Time  :2015-8-4 12:10:11
 8 File Name     :G.cpp
 9 ************************************************/
10 
11 #include <cstdio>
12 #include <algorithm>
13 #include <iostream>
14 #include <sstream>
15 #include <cstring>
16 #include <cmath>
17 #include <string>
18 #include <vector>
19 #include <queue>
20 #include <deque>
21 #include <stack>
22 #include <list>
23 #include <map>
24 #include <set>
25 #include <bitset>
26 #include <cstdlib>
27 #include <ctime>
28 using namespace std;
29 
30 #define lson l, mid, rt << 1
31 #define rson mid + 1, r, rt << 1 | 1
32 typedef long long ll;
33 const int MAXN = 1e5 + 10;
34 const int INF = 0x3f3f3f3f;
35 const int MOD = 1e9 + 7;
36 multiset<int>::iterator it; 
37 
38 inline int read(void)
39 {
40     int x = 0, f = 1;    char ch = getchar ();
41     while (ch < 0 || ch > 9)    {if (ch == -)    f = -1;    ch = getchar ();}
42     while (ch >= 0 && ch <= 9)    {x = x * 10 + ch - 0;    ch = getchar ();}
43     return x * f;
44 }
45 
46 int main(void)    {     //HDOJ 5349 MZL‘s simple problem
47     int n;
48     while (scanf ("%d", &n) == 1)   {
49         multiset<int> S;
50         for (int i=1; i<=n; ++i)    {
51             int op, x;  
52             op = read ();
53             if (op == 1)    {
54                 x = read ();
55                 S.insert (x);
56             }
57             else if (op == 2)   {
58                 if (S.empty ()) continue;
59                 S.erase (S.begin ());
60             }
61             else if (op == 3)   {
62                 if (S.empty ()) {
63                     puts ("0"); continue;
64                 }
65                 it = S.end ();   it--;
66                 printf ("%d\n", *it);
67             }
68         }
69     }
70 
71     return 0;
72 }
技术分享
 1 /************************************************
 2  * Author        :Running_Time
 3  * Created Time  :2015-8-5 16:42:43
 4  * File Name     :G_2.cpp
 5  ************************************************/
 6 
 7 #include <cstdio>
 8 #include <algorithm>
 9 #include <iostream>
10 #include <sstream>
11 #include <cstring>
12 #include <cmath>
13 #include <string>
14 #include <vector>
15 #include <queue>
16 #include <deque>
17 #include <stack>
18 #include <list>
19 #include <map>
20 #include <set>
21 #include <bitset>
22 #include <cstdlib>
23 #include <ctime>
24 using namespace std;
25 
26 #define lson l, mid, rt << 1
27 #define rson mid + 1, r, rt << 1 | 1
28 typedef long long ll;
29 const int MAXN = 1e5 + 10;
30 const int INF = 0x3f3f3f3f;
31 const int MOD = 1e9 + 7;
32 
33 inline int read(void)
34 {
35     int x = 0, f = 1;    char ch = getchar ();
36     while (ch < 0 || ch > 9)    {if (ch == -)    f = -1;    ch = getchar ();}
37     while (ch >= 0 && ch <= 9)    {x = x * 10 + ch - 0;    ch = getchar ();}
38     return x * f;
39 }
40 
41 int main(void)    {
42     int n;  n = read ();
43     int sz = 0, mx = -2e9;
44     for (int i=1; i<=n; ++i) {
45         int op, x;  op = read ();
46         if (op == 1)    {
47             x = read ();
48             sz++;   mx = max (mx, x);
49         }
50         else if (op == 2)   {
51             sz = max (0, sz - 1);
52             if (!sz)  mx = -2e9;
53         }
54         else    {
55             if (!sz)    puts ("0");
56             else    printf ("%d\n", mx);
57         }
58     }
59 
60     return 0;
61 }
标称做法

 

mutiset HDOJ 5349 MZL's simple problem

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/4705213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!