Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 58581 Accepted Submission (s): 23023
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.
Sample INPUT8 389 207 155 300 299 170 158 65
Sample Output2
SOURCE Zhejiang University of Technology fourth session of college students Program design contest
recommendjgshining | We have carefully selected several similar problems for you:1176 1003 1159 1087 1231 requires that the lowest queue is discharged in the order given, each queue is non-ascending, and the longest rise is obtained The length of the subsequence is the minimum number of queues. Code:
#include <iostream>#include<cstdio>#include<algorithm>#defineINF 0x3f3f3f3f#defineMAX 100000using namespacestd;intN;intS[max];intMain () {intD; while(~SCANF ("%d",&N)) {intc =0; for(inti =0; i < N;i + +) {scanf ("%d",&d); if(D >S[c]) {s[+ + c] =D; } Else { intL =0, r =C,mid; while(L <r) {Mid= (L + r)/2; if(S[mid] < D) L = mid +1; ElseR =mid; } S[l]=D; }} printf ("%d\n", c); }}
Then is a greedy approach, in fact, think carefully, the same reason, Lis is a knowledge of dynamic planning, requires at least a few degradation sequence, requires the longest ascending sub-sequence, the following greedy is actually, every time to find the highest interception height of the system to intercept, as for those high height of course left behind high shells, If you can't intercept it, it's a happy system.
Code:
#include <iostream>#include<cstdio>#include<algorithm>#defineINF 0x3f3f3f3f#defineMAX 100000using namespacestd;intN;intS[max];intMain () {intD; while(~SCANF ("%d",&N)) {intc =0; for(inti =0; i < N;i + +) {scanf ("%d",&d); intMini = Inf,t =-1; for(intj =0; J < C;j + +) { if(S[j] >= d && S[j] < mini) Mini = S[j],t =J; } if(t = =-1) S[c + +] =D; ElseS[T] =D; } printf ("%d\n", c); }}
HDU 1257 Minimum interception system