解题思路:用一个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. Android——ListView相关作业(修改版)

    给GridView提供点击按钮添加新数据,单击项目修改,长按删除功能 activity_practise7的layout文件: <?xml version="1.0" enc ...

  2. Python爬虫学习笔记——防豆瓣反爬虫

    开始慢慢测试爬虫以后会发现IP老被封,原因应该就是单位时间里面访问次数过多,虽然最简单的方法就是降低访问频率,但是又不想降低访问频率怎么办呢?查了一下最简单的方法就是使用转轮代理IP,网上找了一些方法 ...

  3. Linux 的多线程编程的高效开发经验(转)

    http://www.ibm.com/developerworks/cn/linux/l-cn-mthreadps/ 背景 Linux 平台上的多线程程序开发相对应其他平台(比如 Windows)的多 ...

  4. Python路径总结

    Windows下文件路径的分隔符是'\'反斜杠,文件路径也是一个字符串,牵扯到'\'在Python字符串中存在转义的情况,就对这个问题做一个探究. Python字符串中要使用'\'时有两种方法: 使用 ...

  5. Git-仓库迁移

    如果你想从别的 Git 托管服务那里复制一份源代码到新的 Git 托管服务器上的话,可以通过以下步骤来操作.1). 从原地址克隆一份裸版本库,比如原本托管于 GitHub. git clone --b ...

  6. C# waitformultipleobjects()

    class WatchThread { [DllImport("kernel32.dll")] private static extern int CreateEvent(IntP ...

  7. C# typeof()实例详解

    typeof(C# 参考) 用于获取类型的 System.Type 对象.typeof 表达式采用以下形式: System.Type type = typeof(int);  备注 若要获取表达式的运 ...

  8. Maximum number of WAL files in the pg_xlog directory (1)

      Guillaume Lelarge: Hi, As part of our monitoring work for our customers, we stumbled upon an issue ...

  9. Linux中/proc/[pid]/status详细说明

    [root@localhost ~]# cat /proc/self/status Name: cat State: R (running) SleepAVG: 88% Tgid: 5783 Pid: ...

  10. C++运算符重载详解

    1.什么是运算符重载 运算符重载是一种函数重载. 运算符函数的格式:operatorop(argument-list)例如,operator+()重载+运算符.其中的op,必须是有效的C++运算符,如 ...