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的更多相关文章

  1. Codeforces 144D Missile Silos 最短路

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  2. zoj 3460 Missile【经典建图&&二分】

    Missile Time Limit: 2 Seconds      Memory Limit: 65536 KB You control N missile launching towers. Ev ...

  3. Missile:双状态DP

    题目 描写叙述 Long , long ago ,country A invented a missile system to destroy the missiles from their enem ...

  4. 最短路 Codeforces Round #103 (Div. 2) D. Missile Silos

    题目传送门 /* 最短路: 不仅扫描边,还要扫描点:点有两种情况,一种刚好在中点,即从u,v都一样,那么最后/2 还有一种是从u,v不一样,两种的距离都是l 模板错了,逗了好久:( */ #inclu ...

  5. Codeforces Round #103 (Div. 2) D. Missile Silos(spfa + 枚举边)

    题目链接:http://codeforces.com/problemset/problem/144/D 思路:首先spfa求出中心点S到其余每个顶点的距离,统计各顶点到中心点的距离为L的点,然后就是要 ...

  6. 算法与数据结构实验题 5.2 Missile

    1.题目: 2.解题思路: 把每个点对应的两条半径求出,之后对d1进行升序排序,对应d2也改变位置.其中一个圆心的半径r1确定之后,除去第一个圆包围的点,在其余点中找到另外一个圆的最长的半径r2,此时 ...

  7. DS实验题 Missile

    题目: 提示:并没有精度问题. 原题 NOIP2010 导弹拦截 思路 设源点为A(x1, y1)和B(x2, y2). 第一步,用结构体存节点,包括以下元素: 1.横坐标x 2.纵坐标y 3.节点和 ...

  8. Missile Command 导弹指令

    发售年份 1980 平台 街机 开发商 雅达利(Atari) 类型 射击 https://www.youtube.com/watch?v=nokIGklnBGY

  9. HDU - 6167: Missile Interception (二分+圆的交)

    pro:二维平面上,给点N个导弹的初始位置,射出方向,速度.问你是找一点,可以从这一点向任意方向发出拦截导弹,速度未V,最小化最大拦截导弹的时间.  如果要拦截一个导弹,必须在导弹发射之后才可以发射拦 ...

随机推荐

  1. CCFlow SDK模式开发

    需求: 1.业务数据要保存在我们自己的数据库里    2.CCFlow有保存草稿的功能,但是领导要求每个业务都要有草稿箱,流程从草稿箱发起,每个业务单独查询,而不要在CCFlow的统一界面查询,所以每 ...

  2. [CLR via C#]8. 方法

    一.实例构造器和类(引用类型) 类实例构造器是允许将类型的实例初始化为良好状态的一种特殊的方法. 类实例构造器方法在"方法定义元数据表"中始终叫.ctor(代表constructo ...

  3. 与众不同 windows phone (40) - 8.0 媒体: 音乐中心的新增功能, 图片中心的新增功能, 后台音乐播放的新增功能

    [源码下载] 与众不同 windows phone (40) - 8.0 媒体: 音乐中心的新增功能, 图片中心的新增功能, 后台音乐播放的新增功能 作者:webabcd 介绍与众不同 windows ...

  4. python学习笔记2(pycharm、数据类型)

    Pycharm 的使用 IDE(Integrated  Development  Environ ment) :集成开发环境 Vim  :经典的linux下的文本编辑器(菜鸟和大神喜欢使用) Emac ...

  5. quartz使用(一)

    在项目中经常会碰到定时任务,quartz是一款非常优秀的开源框架, 提供了定时任务的支持,还支持任务的持久化,并且提供了对数据库的支持.下面首先对quartz做一个简单介绍,并附上一个小例子. 1.下 ...

  6. 环境搭建二 secureCRT配置

    上一篇里面讲到了虚拟机安装,以及secureCRT的远程连接.此篇文章介绍secureCRT的配置. 颜色设置 参考   http://jingyan.baidu.com/article/a681b0 ...

  7. Linux chmod命令详解

    Linux chmod命令详解 chmod----改变一个或多个文件的存取模式(mode)   chmod [options] mode files   只能文件属主或特权用户才能使用该功能来改变文件 ...

  8. 自定义View_2_关于自定义组合View

    自定义View(2) Android当中给我们提供了丰富的UI控件,当然也许满足不了我们的需求,我们就必须学会自定义自己的View,我们怎么算是自定义自己的view呢! 我们会根据原来有的View对V ...

  9. centos/rhel 6.5下rabbitmq安装(最简单方便的方式)

    wget -c http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.x86_64.r ...

  10. mysql root用户kill connection报ERROR 1095 (HY000): You are not owner of thread N

    今日某系统mysql root用户kill connection时报ERROR 1095 (HY000): You are not owner of thread N 按说通过root用户具有supe ...