【贪心】HDU 1257
题意:中文题不解释。
思路:网上有说贪心有说DP,想法就是开一个数组存每个拦截系统当前最高能拦截的导弹高度。输入每个导弹高度的时候就开始处理,遍历每一个拦截系统,一旦最高拦截高度比它高,就把当前拦截系统的高度调整为它的高度,如果访问到末尾都没有能拦截的系统,那么拦截系统加一。
P.S:听说这题杭电数据有点水
/**
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
**/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 300005;
int dp[maxn];
int n;
int main()
{
while(~scanf("%d",&n)){
memset(dp,0,sizeof(dp)); //仅仅需要dp[0] = 0就可以
int flag; //标记是否能被当前已有的拦截系统拦截
int x;
int res = 0;
for(int i=0;i<n;i++){
scanf("%d",&x);
flag = 1;
for(int j=0;j<=res;j++){
if(dp[j]>x){
dp[j] = x;
flag = 0;
break;
}
}
if(flag){
res++;
dp[res] = x;
}
}
printf("%d\n",res);
}
return 0;
}
【贪心】HDU 1257的更多相关文章
- POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心
参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...
- HDU 1257 最少拦截系统 (DP || 贪心)
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- HDU 1257 最少拦截系统(Dilworth定理+LIS)
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- 怒刷DP之 HDU 1257
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- HDU 1257——最少拦截系统——————【LIS变型题】
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- HDU 1257 最少拦截系统 最长递增子序列
HDU 1257 最少拦截系统 最长递增子序列 题意 这个题的意思是说给你\(n\)个数,让你找到他最长的并且递增的子序列\((LIS)\).这里和最长公共子序列一样\((LCS)\)一样,子序列只要 ...
- hdu 1257 最少拦截系统(简单贪心)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1257 虽然分类是dp感觉还是贪心 比较水 #include <iostream> #inclu ...
- hdu 1257 && hdu 1789(简单DP或贪心)
第一题;http://acm.hdu.edu.cn/showproblem.php?pid=1257 贪心与dp傻傻分不清楚,把每一个系统的最小值存起来比较 #include<cstdio> ...
- HDU 1257 最少拦截系统(贪心 or LIS)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- windows 下搭建简易nginx+PHP环境
2016年11月19日 14:40:16 星期六 官网下载 nginx, php windows下的源码包(windows下不用安装, 解压即可) 修改配置文件, (稍后补上) 路径如下: 启动脚本: ...
- 解决NetBeans运行web项目时出现的“未能正确设置java DB”问题
1.在NetBeans导航器中,点击"服务"选项卡: 2.展开"数据库"菜单: 3.在"Java DB"上右键 –> 选择" ...
- c/c++ string
string类的定义.操作. #include<iostream> #include<string> using namespace std; int main() { // ...
- MVC Code First 自动生成数据库
1.新建一个MVC项目
- js中的斐波那契数列法
//斐波那契数列:1,2,3,5,8,13…… //从第3个起的第n个等于前两个之和 //解法1: var n1 = 1,n2 = 2; for(var i=3;i<101;i++){ var ...
- 假如 UNION ALL 里面的子句 有 JOIN ,那个执行更快呢
比如: select id, name from table1 where name = 'x' union all select id, name from table2 where name = ...
- splice() 方法向/从数组中添加/删除项目,然后返回被删除的项目
删除位于 index 2 的元素,并添加一个新元素来替代被删除的元素: <script type="text/javascript"> var arr = new Ar ...
- java模拟浏览器上传文件
public static void main(String[] args) { String str = uploadFile("C:/Users/RGKY/Desktop/wKgBHVb ...
- hdu 2222 Keywords Search
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2222 思路:裸AC自动机,直接贴代码做模板 #include<stdio.h> #includ ...
- opencv计算运行时间
double Time = (double)cvGetTickCount();// 算法过程Time = (double)cvGetTickCount() - Time ; printf( &quo ...