HDU1257 Minimum interception system

Source: Internet
Author: User
Tags radar

Title Requirements:

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: Total number of missiles (positive integers), the height at which missiles fly (radar-given height data is a positive integer not greater than 30000, separated by a space)

Output corresponds to each set of data outputs to intercept all missiles with a minimum of how many sets of such missile interception systems.

Problem Solving Ideas:

When I first saw this problem, it was particularly simple, that is, each time compared to the height of the previous missile, it increased by 1. After a careful thought there was a problem, perhaps the next missile was higher than the current height, the missile could not intercept, but it could still continue to intercept the subsequent height less than his missiles.

With this idea, set an array of cannon[], where cannon[i] is used to store the maximum height that the block I interception system can currently intercept. Each time a missile is read into the height of the current interception system to find out whether the current interception height can intercept, if so, then the maximum height of the system to intercept it becomes the current missile height, if not, a new interception system, the maximum interception height is the current missile height.

The code is as follows:

# include <iostream># include <algorithm>using namespace Std;int cannon[10000];int main () {Freopen (" Input.txt "," R ", stdin), int n;while (scanf ("%d ", &n)!=eof && N) {memset (cannon,0,sizeof (cannon)); int I,j, Count,x;cannon[0]=0;count=0;for (i=0;i<n;i++) {scanf ("%d", &x); for (j=0;j<count;j++) {if (X<=cannon[j]) {cannon[j]=x;break;}} if (j==count) {cannon[j++]=x;count++;}} printf ("%d\n", count);} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU1257 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.