Problem description A missile interception system developed by a country to defend against enemy missile attacks. But there is a flaw in this missile interception system: Although its first shells can reach any height, each shot cannot exceed the height of the previous one. Someday, The radar captures the enemy's missiles. Since the system is still in trial, there is only one set of systems that may not intercept all missiles.
What do we do? How many systems do you have? It's easy to say it. Cost is a big problem. So I came here to call for help, please figure out how many sets of interception systems you need at least. Input enters several sets of data. Each group of data includes the total number of missiles (positive integers), the missile's altitude (the altitude data given by the radar is a positive integer of not more than 30000, separated by a space) output corresponds to each set of data outputs the minimum number of such missile interceptors to be equipped to intercept all missiles. Sample INPUT8 389 207 155 299, 158, sample Output2
Problem Solving Ideas:
Greed;
the minimum number of requirements, so that the existing system interception height to reach the highest possible;
so each time the missile input, let the low to intercept, low stop to find high;
1#include <iostream>2#include <algorithm>3 using namespacestd;4 intMain ()5 {6 intN,b,num;7 while(cin>>N)8 {9 inta[ +]={0};TenCin>>b; Onea[0]=b; Anum=1; - for(intI=2; i<=n;i++) - { theCin>>b; - BOOLflag=1; - for(intI=0; i<num;i++) - { + if(a[i]>=b) - { +a[i]=b; Aflag=0; at Break; - } - } - if(flag) - { -a[num++]=b; in } -Sort (a,a+num); to } +cout<<num<<Endl; - } the}
HDU 1257-Minimum interception system