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. C语言数组内存初始化

    内存初始化当然有必然,但是不用memset,直接这样写就可以了:char* szRemoteFile = new char[MAX_LENGTH](); http://blog.csdn.net/pa ...

  2. python OptionParser模块

    Python中强大的选项处理模块. #!/usr/bin/python from optparse import OptionParser parser = OptionParser() parser ...

  3. CodeIgniter结合Bootstrap

    CodeIgniter-Bootstrap结合了 cI和bootstrap的长处,一个专注于服务器端,一个专注于ui,这个把2个结合起来了.框架地址: http://www.andyhawthorne ...

  4. elk 添加节点

    elk 添加节点: cluster.name: es_cluster node.name: node03 path.data: /elk/elasticsearch/data path.logs: / ...

  5. libcurl的使用问题“Expect100-continue”

    最近在做团购酒店APP分享到qzone功能,使用libcurl访问qzone的分享cgi接口,酒店分享信息以POST方式传输,在测试的时候发现分享接口平均有2s的延迟,这延迟也太大了吧,于是乎问了空间 ...

  6. Oracle 使用RMAN

    RMAN 数据库备份 特点: . 跳过未使用的数据块 . 备份压缩 . 执行增量备份 . 块级别的恢复 组件: . RMAN命令执行器(RMAN Executable) . 目标数据库(Traget ...

  7. java学习之坦克大战游戏

    总结:由于这几天快过年比较忙然后没怎么写,写代码途中一些经验总结现在给忘记了.这次的小项目感觉比上次写的思路清楚了点.没有之前第一次写那么逻辑混乱,结构也搞的比之前的要好,添加功能比较容易.学习了之前 ...

  8. HTTP学习笔记--HTTP报文

    报文流     HTTP报文在客户端.服务器和代理之间流动.“流入”.“流出”.“上游”.“下游”这些术语用来描述报文方向. 报文流入源端服务器     流入:流向服务器     流出:流向用户Age ...

  9. git 无法添加文件夹下文件

    最近做项目时,发现无法提交某个子文件夹下的文件. google后发现可能是该子文件夹下有.git文件夹导致无法上传. 删除子文件夹下.git后,依然无法提交子文件夹下的文件. 继续google, 尝试 ...

  10. Tomcat7.0.22在Windows下详细配置过程

    Tomcat7.0.22在Windows下详细配置过程 一.JDK1.7安装 1.下载jdk,下载地址:http://www.oracle.com/technetwork/java/javase/do ...