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. C#版本的历史

    + 展开目录 - 版本号的一些命名规则 - 语言,运行时,类库,开发工具的区 - 2002年 C#1.0发布 - 2005年 C#2.0发布 - 2007年 C#3.0发布 - 2010年 C#4.0 ...

  2. 重构第8天:使用委托代替继承(Replace Inheritance with Delegation)

    理解:根本没有父子关系的类中使用继承是不合理的,可以用委派的方式来代替. 详解:我们经常在错误的场景使用继承.继承应该在仅仅有逻辑关系的环境中使用,而很多情况下却被使用在达到方便为目的的环境中. 看下 ...

  3. C#全角转换成半角并检查

    新建一个项目quanbanjiao,在此项目下新建一个类Class1 using System; using System.Web; using System.Text; namespace quan ...

  4. 【C++】第1章 在VS2015中用C++编写控制台应用程序

    分类:C++.VS2015 创建日期:2016-06-12 一.简介 看到不少人至今还在用VC 6.0开发工具学习C++,其实VC 6.0开发工具早就被淘汰了.这里仅介绍学习C++时推荐使用的两种开发 ...

  5. [Eclipse] - 解决导入flask模块出现的Unresolved Import flask问题

    http://www.cnblogs.com/mizhon/p/4242073.html [Eclipse] - 解决导入flask模块出现的Unresolved Import flask问题 最近想 ...

  6. 设计模式之桥接模式(Bridge)

    注:本文不属于原创,而是根据原文重新整理,原文是:我给媳妇解释设计模式:第一部分 设计模式不是基于理论发明的.相反,总是先有问题场景,再基于需求和情景不断演化设计方案,最后把一些方案标准化成“模式”. ...

  7. javascript数组浅谈3

    前两节说了数组最基本的创建,队列方法,排序和一些操作方法,这节说说迭代和归并方法. every()方法 & some()方法 这两个方法会对数组中的每一项运行给定函数,然后返回一个布尔值,理解 ...

  8. teambition的热血团队

    一群热血年轻人开发了一套项目协作软件teambition,无意帮他们宣传,更多见网址www.teambition.com. 网站上简短的一段话,深深的打动了我.他们说teambition: 由热爱工作 ...

  9. Objective-C

    1.OC基础 第一个OC的类 Objective-C: 字符串NSString与NSMutableString iOS开发的入门总结的第一篇 iOS开发的入门总结的第二篇

  10. Redis介绍及常用命令

    一 Redis介绍 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15日起,Redis的开发 ...