10901 Missile
10901 Missile
时间限制:1000MS 内存限制:65535K
提交次数:40 通过次数:7
Description
Long, long ago, country A invented a missile system to destroy the missiles from their enemy. That system can launch only one missile to destroy multiple missiles if the heights of all the missiles form a non-decrease sequence.
But recently, the scientists found that the system is not strong enough. So they invent another missile system. The new system can launch one single missile to destroy many more enemy missiles. Basically, the system can destroy the missile from near to far. When the system
is begun, it chooses one enemy missile to destroy, and then destroys a missile whose height is lower and farther than the first missile. The third missile to destroy is higher and farther than the second missile... the odd missile to destroy is higher and farther than the previous one, and the even missile to destroy is lower and farther than the previous one.
Now, given you a list of the height of missiles from near to far, please find the most missiles that can be destroyed by one missile launched by the new system.
输入格式
The input contains multiple test cases.
In each test case, first line is an integer n (0<n≤1000), which is the number of missiles to destroy. Then follows one line which contains n integers (≤109), the height of the missiles followed by distance.
The input is terminated by n=0.
输出格式
For each case, print the most missiles that can be destroyed in one line.
输入样例
4
5 3 2 4
3
1 1 1
0
输出样例
3
1
题意:
n代表导弹数目,然后从高到远给出导弹的高度,
求最多能打下导弹个数,比且打下来的第偶数个导弹要比前一个矮且远,第奇数个导弹要比前一个
高且远。
DP题:
#include <stdio.h>
#include <stdlib.h>
int dp[],a[]; int max(int a,int b)
{
return a>b?a:b;
} int main()
{
int n,i,t,j;
while(scanf("%d",&n)&&n)
{ for(i=;i<n;i++){
scanf("%d",&a[i]);
dp[i]=;
} for(i=,t=; i<n; i++)
{
for(j=;j<i;j++)
if((dp[j]%==&&a[i]<a[j])||(dp[j]%==&&a[i]>a[j]))
dp[i]=max(dp[j]+,dp[i]);
t=max(t,dp[i]);
}
printf("%d\n",t);
} return ;
}
10901 Missile的更多相关文章
- Codeforces 144D Missile Silos 最短路
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- zoj 3460 Missile【经典建图&&二分】
Missile Time Limit: 2 Seconds Memory Limit: 65536 KB You control N missile launching towers. Ev ...
- Missile:双状态DP
题目 描写叙述 Long , long ago ,country A invented a missile system to destroy the missiles from their enem ...
- 最短路 Codeforces Round #103 (Div. 2) D. Missile Silos
题目传送门 /* 最短路: 不仅扫描边,还要扫描点:点有两种情况,一种刚好在中点,即从u,v都一样,那么最后/2 还有一种是从u,v不一样,两种的距离都是l 模板错了,逗了好久:( */ #inclu ...
- Codeforces Round #103 (Div. 2) D. Missile Silos(spfa + 枚举边)
题目链接:http://codeforces.com/problemset/problem/144/D 思路:首先spfa求出中心点S到其余每个顶点的距离,统计各顶点到中心点的距离为L的点,然后就是要 ...
- 算法与数据结构实验题 5.2 Missile
1.题目: 2.解题思路: 把每个点对应的两条半径求出,之后对d1进行升序排序,对应d2也改变位置.其中一个圆心的半径r1确定之后,除去第一个圆包围的点,在其余点中找到另外一个圆的最长的半径r2,此时 ...
- DS实验题 Missile
题目: 提示:并没有精度问题. 原题 NOIP2010 导弹拦截 思路 设源点为A(x1, y1)和B(x2, y2). 第一步,用结构体存节点,包括以下元素: 1.横坐标x 2.纵坐标y 3.节点和 ...
- Missile Command 导弹指令
发售年份 1980 平台 街机 开发商 雅达利(Atari) 类型 射击 https://www.youtube.com/watch?v=nokIGklnBGY
- HDU - 6167: Missile Interception (二分+圆的交)
pro:二维平面上,给点N个导弹的初始位置,射出方向,速度.问你是找一点,可以从这一点向任意方向发出拦截导弹,速度未V,最小化最大拦截导弹的时间. 如果要拦截一个导弹,必须在导弹发射之后才可以发射拦 ...
随机推荐
- Requested registry access is not allowed(不允许所请求的注册表访问权)
尝试创建自定义事件日志时,将会收到“Requested registry access is not allowed(不允许所请求的注册表访问权)”错误消息 EventLog.CreateEventS ...
- Unity中简单使用Opengl
简介 由于项目特殊需求,需要在unity中使用一些OpenGL的东西来绘制图形(PS:其实就是有一个拖尾算法只有OpenGL版本~~~懒得改了,直接在unity中使用OpenGL算了).所以琢磨咯下如 ...
- C#调用windows api示例
这是运行结果: Api函数是构筑Windws应用程序的基石,每一种Windows应用程序开发工具,它提 供的底层函数都间接或直接地调用了Windows API函数,同时为了实现功能扩 展,一般也都提供 ...
- ASP.NET使用UpdatePanel实现AJAX
ScriptManager和UpdatePanel控件联合使用可以实现页面异步局部更新的效果.其中的UpdatePanel就是设置页面中异 步局部更新区域,它必须依赖于ScriptManager存在, ...
- Foreach能够循环的本质
我们对foreach循环并不陌生,在C#中我们用得非常多,但是我们是否清楚foreach循环的本质呢? 众所周知,foreach循环能够遍历 数组 ,集合 .但是我们自己定义的一个类是否能够通过fo ...
- jquery实现网页选项卡
这个功能在现在的网站中使用较为普遍,就是以选项卡的形式来对一些内容做了分类.,比如下面的天猫商城. 下面的源码是仿照天猫写的一个选项卡,实现起来的效果如下. 主要是利用我们在点击相应板块是触发它的单击 ...
- MySQL的字符集
MySQL的字符集支持(Character Set Support)有两个方面:字符集(Character set)和排序方式(Collation). 字符(Character)是指人类语言中最小的表 ...
- python面向对象(一),Day6
connfigparser模块 xml模块 shutil模块以及压缩解压 subprocess模块 面向对象(上) 类和对象 onfigParser 用于对特定的配置进行操作,当前模块的名称在 pyt ...
- Durandal介绍
Durandal是一个JS框架用于构建客户端single page application(SPAs).它支持MVC,MVP与MVVM前端构架模式.使用RequireJS做为其基本约定层,D ...
- CSS3中的box-shadow
语法: box-shadow: h-shadow v-shadow blur spread color inset; box-shadow 向框添加一个或多个阴影.该属性是由逗号分隔的阴影列表,每个阴 ...