解题思路:用一个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;
}

HDU 1257 最少拦截系统(贪心)的更多相关文章

  1. hdu 1257 最少拦截系统(贪心)

    解题思路:[要充分理解题意,不可断章取义] 贪心:每个防御系统要发挥其最大性能, 举例: Input : 9 389 207 155 300 299 170 155 158 65 Output: 2 ...

  2. HDU 1257 最少拦截系统 最长递增子序列

    HDU 1257 最少拦截系统 最长递增子序列 题意 这个题的意思是说给你\(n\)个数,让你找到他最长的并且递增的子序列\((LIS)\).这里和最长公共子序列一样\((LCS)\)一样,子序列只要 ...

  3. HDU 1257 最少拦截系统(贪心 or LIS)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)   ...

  4. HDU 1257最少拦截系统[动态规划]

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1257                                                 最 ...

  5. hdu 1257 最少拦截系统【贪心 || DP——LIS】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  6. HDU 1257 最少拦截系统 (DP || 贪心)

    最少拦截系统 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  7. hdu 1257 最少拦截系统(动态规划 / 贪心)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  8. POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)

    Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...

  9. HDU——1257最少拦截系统(贪心)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  10. HDU 1257 最少拦截系统(Dilworth定理+LIS)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

随机推荐

  1. POJ3308 Paratroopers(网络流)(最小割)

                                                     Paratroopers Time Limit: 1000MS   Memory Limit: 655 ...

  2. PHP太怪了,in_array() ,strpos,

    PHP中在某个字符中查找另外一个字符串,是否存在,用的是strpos,此函数用法,经常很多人用反了,正确的用法是strpos(string,search),strstr等,前面是原字符串,后面是要在原 ...

  3. 自定义颜色显示的CheckBox

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. apache性能优化

    perfork进程数 http://sookk8.blog.51cto.com/455855/275759/ mod_cache 磁盘缓存 http://www.cnblogs.com/fnng/ar ...

  5. git 教程 ,常用命令

    Git使用手册 http://www.cnblogs.com/lantingji/p/5942721.html git官网 https://git-scm.com/ Git的奇技淫巧 http://w ...

  6. 谓词的使用 -ios

    #import <Foundation/Foundation.h> @interface Person : NSObject<NSCopying> @property(nona ...

  7. Linux共享内存

    1.什么是共享内存在前面讲虚拟内存机制时,有讲到Linux的内存映射机制:初始化虚拟内存区域时,会把虚拟内存和磁盘文件对象对应起来.由于内存映射机制,一个磁盘文件对象可被多个进程共享访问,也可被多个进 ...

  8. vb6动态创建webbrowser

    Option Explicit Private WithEvents IE As VBControlExtender Private Sub Command1_Click() Dim IE Set I ...

  9. 详尽介绍FireFox about:config

    一.什么是about:config about: config: 是Firefox的设置页面,Firefox提供了不少高级设置选项在这里以便让你可以更加详细地控制Firefox的运行方式.官方不推荐 ...

  10. Android App监听软键盘按键的三种方式

    前言:   我们在android手机上面有时候会遇到监听手机软键盘按键的时候,例如:我们在浏览器输入url完毕后可以点击软键盘右下角的“GO”按键加载url页面:在点击搜索框的时候,点击右下角的sea ...