Missile interception--optimization algorithm

Source: Internet
Author: User

A missile interception system has been developed by a country to defend against enemy missile attacks. But the missile interception system has a flaw: although its first artillery shells can reach any height, each projectile cannot be higher than the previous one. One day, the radar caught the enemy's missiles to attack. Since the system is still in the trial phase, there is only one set of systems that may not intercept all missiles.

The height of the input missiles in turn (the radar gives a positive integer of not more than 30000), calculates how many missiles the system can intercept, and outputs the minimum number of such missile interceptors to be equipped to intercept all missiles.

First ask, very simple, longest not ascending subsequence + priority queue, O (NLOGN)

The second question, can be converted into the longest ascending subsequence (oneself want), time complexity ibid.

1 var2 s,s2:string;3 I,j,t,n,tail:longint;4A,queue:Array[0..10000] ofLongint;5 functionPosdown (value:longint): Longint;6 var7 Middle,left,right:longint;8 begin9left:=1;Tenright:=tail+1; One    whileLeft<right Do A   begin -middle:= (Left+right)Div 2; -     ifQueue[middle]>=value ThenLeft:=middle+1 the     Elseright:=Middle; -   End; -posdown:=Left ; - End; + functionPosup (value:longint): Longint; - var + Middle,left,right:longint; A begin atleft:=1; -right:=tail+1; -queue[right]:=Maxlongint; -    whileLeft<right Do -   begin -middle:= (Left+right)Div 2; in     ifQueue[middle]<value ThenLeft:=middle+1 -     Elseright:=Middle; to   End; +posup:=Left ; - End; the begin * Readln (s); $s:=s+' ';Panax Notoginsengj:=1; -    fori:=1  toLength (s) Do the   begin +     ifs[i]=' '  Then A     begin the Inc (n); +S2:=copy (s,j,i-j); - Val (s2,a[n],t); $j:=i+1; $     End; -   End; -tail:=0; the    fori:=1  toN Do -   beginWuyir:{Posdown (A[i]); thequeue[t]:=A[i]; -     ifT>tail ThenInc (tail); Wu   End; - writeln (tail); Abouttail:=0; $Fillchar (queue,sizeof (t),0); -    fori:=1  toN Do -   begin -t:=Posup (A[i]); Aqueue[t]:=A[i]; +     ifT>tail ThenInc (tail); the   End; - writeln (tail); $ End.

Missile interception--optimization algorithm

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.