[HDU 5349] MZL's simple problem 神题
2015-08-06 15:28
176 查看
http://acm.hdu.edu.cn/showproblem.php?pid=5349
题意:开始输入一个 n 表示有 n 个操作
1 x :插入一个数 x 。
2:删除最小的数
3:查询最大的数。
思路:题目看完有木有觉得很像平衡树?,相用平衡树,multiset,优先队列神马的都去面壁吧。。。我刚刚面壁回来了。。。
其实这是个非常简单的题,我觉得这题出的很好,非常好。。做题越多的人越容易想复杂,,通过这题我发现我的思想已经被禁锢了。。。今天在群里有个人问了这题,,我看了他的写法觉得这尼玛很有问题啊(主要是写的太简单。。),但是又找不到问题。。QwQ,,最后仔细一想还真就这么简单。。
思路:因为删除是最小的,查找是最大的,所以操作过程中是不会删除掉最大值(除非删除最后一个),只要保存最大的值就行了。还加个计数的,数量是 0 查询的时候就输出 0。就这么简单 有木有,有木有。。。
题意:开始输入一个 n 表示有 n 个操作
1 x :插入一个数 x 。
2:删除最小的数
3:查询最大的数。
思路:题目看完有木有觉得很像平衡树?,相用平衡树,multiset,优先队列神马的都去面壁吧。。。我刚刚面壁回来了。。。
其实这是个非常简单的题,我觉得这题出的很好,非常好。。做题越多的人越容易想复杂,,通过这题我发现我的思想已经被禁锢了。。。今天在群里有个人问了这题,,我看了他的写法觉得这尼玛很有问题啊(主要是写的太简单。。),但是又找不到问题。。QwQ,,最后仔细一想还真就这么简单。。
思路:因为删除是最小的,查找是最大的,所以操作过程中是不会删除掉最大值(除非删除最后一个),只要保存最大的值就行了。还加个计数的,数量是 0 查询的时候就输出 0。就这么简单 有木有,有木有。。。
[code]#include <cstdio> #include <cstring> #include <iostream> using namespace std; const int inf = (1 << 31) - 1; int main() { int n; while(~scanf("%d", &n)){ int x, counts = 0, maxn = -inf; while(n--){ scanf("%d",&x); if(x == 1){ scanf("%d", &x); maxn = x > maxn ? x : maxn; counts ++; } else if(x == 2){ if(counts){ counts --; if(counts == 0) maxn = -inf; } } else if(x == 3){ if(counts == 0) printf("0\n"); else printf("%d\n", maxn); } } } return 0; }
相关文章推荐
- 数据结构基础(15) --基数排序
- 验证码的生成
- C语言的数据类型
- JS提交表单
- mysql 误删root
- 基于Google App Engine 的翻F墙Q工具XX-NET部署全套攻略
- 你所需要知道的一些git 的使用命令:历史
- 线程安全与并发安全探究(二)
- Android学习遇到的问题及总结
- 手游反外挂
- phpwind和discuz
- Spring Web MVC 的HandlerMapping的使用之-------SimpleUrlHandlerMapping(有三种配法)
- H5表单类型
- JAVA基础篇五(Java,C++中的容器类)
- CSS3属性选择器
- Shell脚本关于屏幕输出的字符进行颜色控制的问题
- Google 镜像站搜集
- 分享》:关于阅读开源项目的源码思路方法
- python监控linux系统信息(流量/内存/cpu/负载/磁盘/运转时间) Centos安装X Window和桌面环境
- 数据结构基础(14) --链式队列的设计与实现