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. 使用 IIS Manager 对 Windows Azure 网站进行远程管理

     最近,我们为客户新增了使用 Windows自带的 IIS管理控制台管理 Azure网站的功能.IIS Manager支持 HTTP over SSL,提供到您的 Windows Azure 网站 ...

  2. [用UpdateLayeredWindow实现任意异形窗口]

    前面提到,我们可以用SetWindowRgn或SetLayeredWindowAttributes实现不规则以及半透明的效果 对于SetWindowRgn,它通过一个Rgn来设置区域,这个Rgn一般可 ...

  3. hdoj 1532 Drainage Ditches(最大网络流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路分析:问题为最大网络流问题,给定一个有向图,需要求解该有向图的最大网络流,使用Edmonds ...

  4. 笔试题引出float数据的存储方式的深究

    笔试题: #include <iostream>#include <stdio.h>#include <string.h>#include <conio.h& ...

  5. poj 2375 Cow Ski Area bfs

    这个题目用tarjan找联通块,缩点,然后统计出入度为0的点理论上是可行的,但问题是会暴栈.考虑到这个题目的特殊性,可以直接用一次bfs找到数字相同且联通的块,这就是一个联通块,然后缩点,统计出入度即 ...

  6. 网页压缩gzip的问题及说明教程

    关于网页压缩gzip的问题及说明教程 最近比较多人反应gzip的问题 在wdcp的后台里已经有gzip功能的选项,也就是说,只要在这里开启了,就已支持 但从最近的问题中发现,基本上都是使用一些在线检测 ...

  7. iOS开展-CocoaPods安装和使用教程

    原文链接: iOS开展-CocoaPods安装和使用教程 修正已经增加了自己的理解. CocoaPods安装和使用教程 Code4App 原创文章.转载请注明出处:http://code4app.co ...

  8. 【转】Ubuntu常用软件合集

    [转]Ubuntu常用软件合集 Ubuntu常用软件合集 我用的使Ubuntu-Kylin14.04,原因呢主要是觉得使本土化的,自带了日历.输入法.优客助手等易于上手的应用.也省的每次安装完原生的系 ...

  9. JavaSE学习总结第04天_Java基础语法3

      04.01 选择结构switch语句的格式及其解释 switch语句的格式: switch(表达式) {    case 值1:语句体1;break;    case 值2:语句体2;break; ...

  10. NOIP2015前

    时间过得好快...明天就要出发去NOIP了...然后再过半年就要省选了....希望自己能取得好成绩吧... NOIP2015 bless all !