mutiset HDOJ 5349 MZL's simple problem
题目传送门
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 }
标程做法
转载于:https://www.cnblogs.com/Running-Time/p/4705213.html
mutiset HDOJ 5349 MZL's simple problem相关推荐
- BZOJ 4679/Hdu5331 Simple Problem LCT or 树链剖分
4679: Hdu5331 Simple Problem 题意: 考场上,看到这道题就让我想起BZOJ4712洪水.然后思路就被带着飞起了,完全没去考虑一条链的情况,于是GG. 解法:先考虑一条链的做 ...
- COJ 1170 A Simple Problem
题目:在一个由N个整数组成的数列中,最多能找到多少个位置连续的整数且其中的最大值与最小值之差不超过K呢? GDKOI 2003 又一道很类似的题(河床)使用的是动态规划,因为数据范围较小(复杂度为O( ...
- HDU2522 A simple problem【分数与小数】
A simple problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- SGU 111 Very simple problem 翻译 题解
111. Very simple problem 每个测试点时间限制: 0.50 sec. 每个测试点内存限制: 4096 KB 给你一个自然数X,输出平方小于或等于X的最大整数. 输入 输入包含一 ...
- 【线段树】【模板】讲解 + 例题1 HDU - 1754 I Hate It (点修改分数)+ 例题二 POJ - 3468 A Simple Problem with Integers(区间加值)
[线段树][模板]讲解 + 例题1 HDU - 1754 I Hate It (点修改分数)+ 例题二 POJ - 3468 A Simple Problem with Integers(区间加值) ...
- 【HDOJ 5399】Too Simple
[HDOJ 5399]Too Simple 函数映射问题 给出m函数 里面有0~m个函数未知(-1) 问要求最后1~n分别相应仍映射1~n 有几种函数写法(已给定的函数不可变 仅仅可更改未知的函数的映 ...
- poj 3243:A Simple Problem with Integers
3243:A Simple Problem with Integers 查看 提交 统计 提示 提问 总时间限制: 5000ms 单个测试点时间限制: 2000ms 内存限制: 131072 ...
- poj3468 A Simple Problem with Integers
http://acm.hust.edu.cn:8080/judge/problem/viewProblem.action?id=14607 题意:题目给你n个数,m个操作,接下来一行给你这n个数,接下 ...
- HDOJ 1914 The Stable Marriage Problem
rt 稳定婚姻匹配问题 The Stable Marriage Problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 6553 ...
最新文章
- 一个完整的Web应用程序部署示例
- 树莓派和微信和服务器,用树莓派搭建微信公共平台
- 无法执行该VI,必须使用LabVIEW完整版开发系统才可以解决该错误
- Linux指令:grep指令详解1
- OAuth2.0 使用 JWT令牌
- iOS Unicode转中文(UTF-8)
- Android控件:在《第一行代码(第二版)》学习RecyclerView的踩坑经过
- CGI与ISAPI的区别
- Overloaded operators
- Machine Learning——Linear Model
- 苹果cmsv10+2022新版海螺影视主题模板“带后台“M3.1全解密版本+萌芽采集插件
- 昆石VOS3000_2.1.6.0.0一键安装教程
- 半同步半异步模式 -------一个架构模式,清晰的结构,高效并发的I/O
- PTA 显示指定范围的素数并求和《越努力越幸运》
- 山西对口升学本科学校计算机,2019山西中职对口升学本科第一批院校录取分数线公布...
- python批量下载文件教程_超简单超详细python小文件、大文件、批量下载教程
- Allegro过孔盖油和过孔开窗设置(部分过孔开窗)
- iOS程序中调用系统自带应用(短信,邮件,浏览器,地图,appstore,拨打电话,iTunes,iBooks )...
- suse修改日期时间命令 2022_11_11
- 新药韦立得(TAF),乙肝抗病毒药是通过作用于病毒繁殖复制时期以杀死病毒
热门文章
- 函数栈帧的创建和销毁图解
- localstorage存mysql_存储localstorage
- 求和符号上下的值怎么打_Excel快速求和的N种方法,一网打尽
- adguard没有核心 core no_新媒体自学宝典(No.24)| 如何借力自媒体平台放大粉丝流量?...
- vnc 树莓派 链接_树莓派 VNC Viewer 远程桌面配置教程
- 系列有什么区别_哈弗的F系列和H系列,有什么区别?
- linux ipc shmget 例子,Linux IPC之共享内存C 事例(示例代码)
- 素数环(nyoj488)
- STM8单片机读取18B20温度传感器
- python中list的切片和range函数