HDU 1257 最少拦截系统(贪心)
2016-05-02 16:08
447 查看
解题思路:
用一个vector存下数据,从头开始非递增遍历,并把符合条件的删除,一次操作,ans++,当vector为空时退出循环。(PS:学到了vector的erase操作,竟然还有返回值,涨姿势了)AC代码:
#include<iostream> #include<cstdio> #include<cstring> #include<vector> using namespace std; int n; vector<int > vei; int main() { while(~scanf("%d",&n)) { int x; for (int i=0; i<n; i++) { scanf("%d",&x); vei.push_back(x); } vector<int>::iterator it; int x1; int ans=0; while(!vei.empty()) { x1=*(vei.begin()); for (it=vei.begin(); it!=vei.end(); ) { x=(*it); if (x1>=x) { it=vei.erase(it);//erase的返回值是下一个元素的迭代器 x1=x; } else { it++; } } ans++; } cout<<ans<<endl; } return 0; }
相关文章推荐
- 新注册
- 四大漏洞入侵博客
- 在Ubuntu系统上安装Ghost博客平台的教程
- PHP多用户博客系统分析[想做多用户博客的朋友,需要了解]第1/3页
- 基于CakePHP实现的简单博客系统实例
- 基于jsp+servlet实现的简单博客系统实例(附源码)
- csdn 博客的css样式 v3
- 如何使用Gitblog和Markdown建自己的博客
- 利用JS生成博文目录及CSS定制博客
- Flask入门教程实例:搭建一个静态博客
- 让写博客成为一种习惯
- 使用微信快捷登录Wordpress博客
- 博客之前在网易安家,现在迁移到了自己开发的blog http://blog.tongbor.com
- OpenAPI 之 开源软件信息预览 ProjectTips
- 自己对博客的计划
- 做一份30字的简历
- 从主流到边缘,博客为什么不行了?
- 里程碑:博客文章阅读数突破1000万