HDU_1257
最少拦截系统
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 31372 Accepted Submission(s): 12313
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
8 389 207 155 300 299 170 158 65
2
<pre name="code" class="cpp">/*
每出现一个导弹, 用当前距离最近的拦截系统去拦截。。不能拦截了就新开一个拦截系统。同时用数组记录每个拦截系统当前的高度。。==贪心
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std; #define INF 0x7fffffff
#define maxn 10000
int dp[maxn]; //表示当前第i个导弹拦截的高度 int main() {
int n;
while (cin >> n) {
int res = 0;
while (n --) {
int x;
cin >> x;
int flag = 0;
int minH = INF;
int tempi;
for (int i = 0; i<res; i++) {
if (x<=dp[i] && dp[i] - x < minH) {
minH = dp[i] - x;
flag = 1;
tempi = i;
}
}
if (flag == 0) {
dp[res++] = x;
}
else dp[tempi] = x;
}
cout << res << endl;
}
return 0;
}
HDU_1257的更多相关文章
随机推荐
- C#Linq技术中SelectMany(...)函数的内部实现的伪代码
我们先来假设这种场景: 一个学校中有多个年级,一个年级有多个班级,一个班级里有多个学生.这里我们只需要班级.年级.和学生这三个概念: 让我们先来定义Class类和Student类: // 注意,Cla ...
- [array] leetCode-27. Remove Element - Easy
27. Remove Element - Easy descrition Given an array and a value, remove all instances of that value ...
- 507. Perfect Number
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divi ...
- nova创建虚拟机源码分析系列之四 nova代码模拟
在前面的三篇博文中,介绍了restful和SWGI的实现.结合restful和WSGI配置就能够简单的实现nova服务模型的最简单的操作. 如下的内容是借鉴网上博文,因为写的很巧妙,将nova管理虚拟 ...
- js代码细嚼慢咽
全局变量的梗 例1: 对于var 的理解:将该变量声明在当前的作用域中,或者说执行上下文中. function add() { result = 3; //result变量即是隐喻全局变量 } add ...
- SharedPreferences 存List集合,模拟数据库,随时存取
PS:SharedPreferences只要稍微学过一点就会用,他本身通过创建一个Editor对象,来存储提交,而editor可以存的格式为 他里面可以存一个Set<String> Set ...
- ES6 函数的扩展(1)
1. 函数参数的默认值 基本用法 在ES6之前,不能直接为函数的参数指定默认值,为了避免这个问题,通常需要先判断一下参数y是否被赋值,如果没有,再等于默认值. ES6允许为函数的参数设置默认值,即直接 ...
- SpringBoot初步
1.创建maven 项目 quickstart类型 2.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" ...
- 利用USearch去除嵌合体(chimeras)
嵌合体序列指在pcr过程中,两条不同的序列产生杂交扩增的序列,属于人工污染,在ITS和16S分析中,应该首先去除,USearch提供去除嵌合体的功能 usearch -uchime_ref reads ...
- 浅谈MVC MVP MVVM
复杂的软件必须有清晰合理的架构,否则无法开发和维护. MVC(Model-View-Controller)是最常见的软件架构之一,业界有着广泛应用. 它本身很容易理解,但是要讲清楚,它与衍生的 MVP ...