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,最小化最大拦截导弹的时间. 如果要拦截一个导弹,必须在导弹发射之后才可以发射拦 ...
随机推荐
- UnityShader快速上手指南(四)
简介 由于其他项目中断了几天更新,继续~~ 这一篇主要是讲光照的(包含漫反射和高光以及多光源的处理) 还是先来看看具体效果(多光源后面单独展示) 有了基本的光照处理之后越来越有立体感了有不有 ╮(╯▽ ...
- sencha 报错问题汇总
store的url必填 否则报错:Uncaught TypeError: Cannot read property 'indexOf' of undefined ext-all.js store必须在 ...
- sql server2008中sql server身份能登录,window身份登录不了
用sql server身份的sa登录成功进入,一切正常,用window身份登录不了,问题如下
- C# winform调用浏览器打开页面方法分享,希望对大家有帮助
在很多客户端程序中我们都需要调用浏览器打开网页,这里分享一个可以在我winform程序调用浏览器的方法,测试通过了. 声明:这个方法是上万个用户测试通过的,不是我没有测试通过就拿出来分享,那个是自己搬 ...
- [转]基于 Quercus 的手游项目终于上线了
原文:http://blog.andsky.com/quercus-php-ngame/ 经过半年的开发,我们第一款手游戏终于开发完毕,架构使用了 netty + Quercus 实现用 php 通过 ...
- 【iOS】Quartz2D简单介绍
一.什么是Quartz2D Quartz 2D是⼀个二维绘图引擎,同时支持iOS和Mac系统 Quartz 2D能完成的工作: 绘制图形 : 线条\三角形\矩形\圆\弧等 绘制文字 绘制\生成图片(图 ...
- Angularjs,WebAPI 搭建一个简易权限管理系统 —— 系统业务与实现(三)
目录 前言 Angularjs名词与概念 Angularjs 基本功能演示 系统业务与实现 WebAPI项目主体结构 Angularjs 前端主体结构 系统业务与实现(二) 上一章我们讲解的 Angu ...
- asp.net 发送邮件
asp.net 发送邮件 System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); msg.To. ...
- 最熟悉的陌生人-------MVC
以前开发iOS程序的时候用的最多的是MVC的设计模式,这种软件架构的模式是由:模型(Model)[屏幕中展示的].视图(View)[如何展示的]和控制器(Controller)[程序的数据 ...
- SQL Server Merge语句的使用
Merge关键字在SQL Server 2008被引入,它能将Insert,Update,Delete简单的并为一句.MSDN对于Merge的解释非常的短小精悍:”根据与源表联接的结果,对目标表执行插 ...