当前位置:网站首页>Dynamic planning question 05_ Missile interception
Dynamic planning question 05_ Missile interception
2022-07-25 11:34:00 【Hard CLZ】
- Title Description :
In order to defend against the missile attack of the enemy , Developing a missile interception system .
But there's a flaw in this interceptor system : Although it can intercept missiles at any height , But every time a missile is intercepted , Its interception ability will be reduced to the height that it can only intercept the last intercepted missile .
One day , The radar caught the enemy's missiles coming , Missiles came in turn , How many missiles can the interception system intercept at most ?- Input:
Enter several data : The altitude at which the missiles fly in turn ( The altitude data given by radar is not greater than 30000 The positive integer , Separate... With spaces ).- Output:
1、 Output the maximum number of missiles this system can intercept .
2、 Output the number of interception systems needed to intercept all missiles
Case input and output :
- Input:
3890 2070 1550 3000 2990 1700 1580 650- Output:
62
#include<iostream>
#include<cstring>
using namespace std;
const int MAX = 1025;
int a[MAX],b[MAX],c[MAX];
int i,maxTp;
int n,m,x;
int main()
{
memset(a,0,sizeof(a)); // Record the Missile Altitude
memset(b,0,sizeof(b)); // Record the maximum non descending sequence length
memset(c,0,sizeof(c));
i = 1;
m = 0; // The maximum number of missiles intercepted by a system
n = 0; // Number of interception systems required
while(cin>>a[i]){
// input data
maxTp = 0;
for(int j=1; j<=i-1; j++){
// The first i The missile in front of the missile And i missile contrast
if((a[j] >= a[i]) && (b[j]>maxTp) )
maxTp = b[j];
}
// Choose the longest sequence Connect
b[i] = maxTp + 1; // add The first i missiles
if(b[i]>m)
m = b[i]; // Maximum number of interceptions
// So far, the first question is completed
x = 0; // In circulation ,x=0, and n May change
for(int j=1; j<=n; j++){
if(c[j]>=a[i])
if(x==0)
x = j;
else
if(c[x] > c[j])
x = j;
}
if(x==0){
// There is at least one interception system by default
n++;
x = n;
}
c[x] = a[i];
i++; // Prepare for the next missile
}
cout<<m<<endl<<n<<endl;
return 0;
}
边栏推荐
猜你喜欢

ArcMap无法启动解决方法

黑客入门教程(非常详细)从零基础入门到精通,看完这一篇就够了。

同事看了我的代码惊呼:居然是这么在Unity中用单例的

圆角大杀器,使用滤镜构建圆角及波浪效果!

MySQL | GROUP_ The concat function concatenates the values of a column with commas

工作面试总遇秒杀?看了京东T8大咖私藏的秒杀系统笔记,已献出膝盖

ArcMap cannot start the solution

小区蔬菜配送的小程序

Hacker introductory tutorial (very detailed) from zero basic introduction to proficiency, it is enough to read this one.

小微企业智能名片管理小程序
随机推荐
There is a newline problem when passing shell script parameters \r
[tree] 100. Same tree
tensorflow入门
同事看了我的代码惊呼:居然是这么在Unity中用单例的
如何判断静态代码质量分析工具的性能?这五大因素必须考虑
大话DevOps监控,团队如何选择监控工具?
使用Three.js实现炫酷的赛博朋克风格3D数字地球大屏
SQL注入 Less18(头部注入+报错注入)
Shell 脚本参数传递时有 \r 换行符问题
MySQL | GROUP_CONCAT函数,将某一列的值用逗号拼接
DNS分离解析的实现方法详解
ESP8266 使用 DRV8833驱动板驱动N20电机
机智云物联网平台 STM32 ESP8266-01S 简单无线控灯
第一个C语言程序(从Hello World开始)
MLX90640 红外热成像仪测温模块开发笔记(五)
Loadbalancerlife lifecycle requested by feign client
Hcip experiment (03)
常见WEB攻击与防御
Leetcode sword finger offer 27. image of binary tree
LVS load balancing lvs-nat building Web Cluster