当前位置:网站首页>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;
}
边栏推荐
- The B2B2C multi merchant system has rich functions and is very easy to open!!!
- C# Newtonsoft. Jason advanced usage
- [IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training
- Getting started with redis
- Hcip experiment (02)
- Learn NLP with Transformer (Chapter 1)
- [树] 100. 相同的树
- 数据库设计-简化字典表[通俗易懂]
- Let sports happen naturally, and fire creates a new lifestyle
- Reinforcement learning (IV)
猜你喜欢

Want to record your supernatural moments when playing games? Let's take a look at how to use unity screenshots

2022 年中回顾|一文看懂预训练模型最新进展

Smart cloud IOT platform STM32 esp8266-01s simple wireless light control

SQL注入 Less18(头部注入+报错注入)

Detailed explanation of zero basis from macro to micro Bert

The most detailed MySQL index analysis (mind map is attached at the end of the article)

B2B2C多商户系统功能丰富,极易二开!!!

SQL language (4)

Mlx90640 infrared thermal imager temperature measurement module development notes (V)

MLX90640 红外热成像仪测温模块开发笔记(五)
随机推荐
Detailed explanation of the implementation method of DNS separation and resolution
SQL language (I)
SQL injection less17 (error injection + subquery)
Several common PCB surface treatment technologies!
tensorflow 调用多块GPU的一些错误
LVS负载均衡之LVS-DR搭建Web群集与LVS结合Keepalived搭建高可用Web群集
Nowcodertop1-6 - continuous updating
如何判断静态代码质量分析工具的性能?这五大因素必须考虑
Common web attacks and defense
基于cornerstone.js的dicom医学影像查看浏览功能
Dataframe print 省略号问题
Why should the hashcode () method be rewritten when rewriting the equals () method
DICOM medical image viewing and browsing function based on cornerstone.js
为什么重写equals()方法必须要重写hashCode()方法
Summary of combination problems of Li Kou brush questions (backtracking)
贪心问题01_活动安排问题
Compressed list ziplist of redis
Hacker introductory tutorial (very detailed) from zero basic introduction to proficiency, it is enough to read this one.
B2B2C多商户系统功能丰富,极易二开!!!
What kind of product power does Hongguang miniev, the top seller of new energy, have?