Testing the CATCHER
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 13968   Accepted: 5146

Description

A military contractor for the Department of Defense has just completed a series of preliminary tests for a new defensive missile called the CATCHER which is capable of intercepting multiple incoming offensive missiles. The CATCHER is supposed to be a remarkable defensive missile. It can move forward, laterally, and downward at very fast speeds, and it can intercept an offensive missile without being damaged. But it does have one major flaw. Although it can be fired to reach any initial elevation, it has no power to move higher than the last missile that it has intercepted.

The tests which the contractor completed were computer simulations of battlefield and hostile attack conditions. Since they were only preliminary, the simulations tested only the CATCHER's vertical movement capability. In each simulation, the CATCHER was fired at a sequence of offensive missiles which were incoming at fixed time intervals. The only information available to the CATCHER for each incoming missile was its height at the point it could be intercepted and where it appeared in the sequence of missiles. Each incoming missile for a test run is represented in the sequence only once.

The result of each test is reported as the sequence of incoming missiles and the total number of those missiles that are intercepted by the CATCHER in that test.

The General Accounting Office wants to be sure that the simulation test results submitted by the military contractor are attainable, given the constraints of the CATCHER. You must write a program that takes input data representing the pattern of incoming missiles for several different tests and outputs the maximum numbers of missiles that the CATCHER can intercept for those tests. For any incoming missile in a test, the CATCHER is able to intercept it if and only if it satisfies one of these two conditions:

The incoming missile is the first missile to be intercepted in this test.

-or-

The missile was fired after the last missile that was intercepted and it is not higher than the last missile which was intercepted.

Input

The input data for any test consists of a sequence of one or more non-negative integers, all of which are less than or equal to 32,767, representing the heights of the incoming missiles (the test pattern). The last number in each sequence is -1, which signifies the end of data for that particular test and is not considered to represent a missile height. The end of data for the entire input is the number -1 as the first value in a test; it is not considered to be a separate test.

Output

Output for each test consists of a test number (Test #1, Test #2, etc.) and the maximum number of incoming missiles that the CATCHER could possibly intercept for the test. That maximum number appears after an identifying message. There must be at least one blank line between output for successive data sets.

Note: The number of missiles for any given test is not limited. If your solution is based on an inefficient algorithm, it may not execute in the allotted time.

Sample Input

389
207
155
300
299
170
158
65
-1
23
34
21
-1
-1

Sample Output

Test #1:
maximum possible interceptions: 6 Test #2:
maximum possible interceptions: 2

Source

题目有点长,意思也有点扯,答案输入输出也很坑,其实就是求最长递减序列!

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=100050;
int a[N],f[N],d[N];
int bsearch(const int *f,int size,const int &a){
int l=0,r=size-1;
while(l<=r){
int mid=(l+r)/2;
if(a<f[mid-1]&&a>=f[mid])return mid;
else if(a>f[mid])r=mid-1;
else l=mid+1;
}
}
int LIS(const int *a,const int &n){
int i,j,size=1;
f[0]=a[0];d[0]=1;
for(i=1;i<n;i++){
if(a[i]>=f[0])j=0;
else if(a[i]<f[size-1])j=size++;
else j=bsearch(f,size,a[i]);
f[j]=a[i];d[i]=j+1;
//for(int k=0;k<size;k++)
// printf(" %d ",f[k]);
//printf("\n");
}
return size;
}
int main()
{
int i,n,t=1;
while(scanf("%d",&a[0])!=EOF&&a[0]!=-1){
for(i=1;;i++)
{
scanf("%d",&a[i]);
if(a[i]==-1)
{
n=i;
break;
}
}
if(t==1)
printf("Test #%d:\n maximum possible interceptions: %d\n",t++,LIS(a,n));
else
printf("\nTest #%d:\n maximum possible interceptions: %d\n",t++,LIS(a,n));
}
return 0;
}

poj1887 Testing the CATCHER的更多相关文章

  1. POJ-1887 Testing the CATCHER(dp,最长下降子序列)

    Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16515 Accepted: 6082 ...

  2. POJ 1887 Testing the CATCHER

    Testing the CATCHER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13396   Accepted: 4 ...

  3. POJ 1887 Testing the CATCHER(LIS的反面 最大递减子序列)

    Language: Default Testing the CATCHER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1 ...

  4. POJ 1887:Testing the CATCHER 求递减序列的最大值

    Testing the CATCHER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16131   Accepted: 5 ...

  5. Poj 1887 Testing the CATCHER(LIS)

    一.Description A military contractor for the Department of Defense has just completed a series of pre ...

  6. UVa 231 - Testing the CATCHER

    题目大意:一种拦截导弹能拦截多枚导弹,但是它在每次拦截后高度不会再升高,给出导弹的序列,问最多能拦截多少枚导弹? 最长递减子序列问题. #include <cstdio> #include ...

  7. 别人整理的DP大全(转)

    动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...

  8. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  9. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

随机推荐

  1. HDU 2152 Fruit

    系数为1的母函数…… #include <cstdio> #include <cstring> using namespace std; int n,m,size[105][2 ...

  2. Installing on CentOS/RHEL / KB forum / Ajenti

    Installing on CentOS/RHEL / KB forum / Ajenti Ajenti → KB → Installation Is it?: Inappropriate Spam ...

  3. 通过自定义window来实现提示框效果

    #import <UIKit/UIKit.h>#import <Foundation/Foundation.h> @interface ZMStatuBarHud : NSOb ...

  4. Android 中文API (70) —— BluetoothDevice[蓝牙]

    前言 本章内容是  android.bluetooth.BluetoothDevice,为Android蓝牙部分的章节翻译.蓝牙设备类,代表了蓝牙通讯国足中的远端设备.版本为 Android  2.3 ...

  5. Android多线程及异步处理问题

    1.问题提出 1)为何需要多线程? 2)多线程如何实现? 3)多线程机制的核心是啥? 4)到底有多少种实现方式? 2.问题分析 1)究其为啥需要多线程的本质就是异步处理,直观一点说就是不要让用户感觉到 ...

  6. JavaScript 高级程序设计(第3版)笔记——chapter7:函数表达式

    一.函数表达式的语法形式 匿名函数 var functionName = function(arg0, arg1, arg2) { //函数体 } 二.函数表达式没有函数提升 var a = 1; i ...

  7. C#中文件管理的运用(Twelfth Day)

    又到了总结的时间了,今天在云和学院学习了文件管理的一些运用及复习昨天学的里氏转换.今天我就总结下昨天遗留下的问题以及今天所学的知识. 昨天遗留的问题 里氏转换(父类转子类) 例:在这里定义父类Peop ...

  8. 【JAVA】使用Eclipse依赖生成jar包时,避免最外层同时生成资源文件的配置。

    使用Eclipse依赖生成jar包时,如果做配置,生成的jar包文件会全部生成在外面,这并不是我们需要的,下面我们一起来修改下配置,使生成的jar包符合我们的需求吧. 1.如果不做任何配置生成的jar ...

  9. Xcode之外的文档浏览工具--Dash (在iOS代码库中浏览本帖)

    链接地址:http://www.cocoachina.com/bbs/read.php?tid=273479 Xcode之外的文档浏览工具--Dash    (在iOS代码库中浏览本帖)       ...

  10. 用jmeter进行多用户并发压力测试 [转]

    近日manager要求对项目进行压力测试,开始对jmeter进行了研究.jmeter是Apache一个开源项目,可对各种项目进行测试,甚至包括junit. 测试要求如下,多用户同时登陆web应用程序, ...