HDU 1257-Minimum interception system

Source: Internet
Author: User
Tags radar

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.