poj1887 Testing the CATCHER
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 13968 | Accepted: 5146 |
Description
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
Output
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的更多相关文章
- POJ-1887 Testing the CATCHER(dp,最长下降子序列)
Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16515 Accepted: 6082 ...
- POJ 1887 Testing the CATCHER
Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 13396 Accepted: 4 ...
- POJ 1887 Testing the CATCHER(LIS的反面 最大递减子序列)
Language: Default Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1 ...
- POJ 1887:Testing the CATCHER 求递减序列的最大值
Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16131 Accepted: 5 ...
- Poj 1887 Testing the CATCHER(LIS)
一.Description A military contractor for the Department of Defense has just completed a series of pre ...
- UVa 231 - Testing the CATCHER
题目大意:一种拦截导弹能拦截多枚导弹,但是它在每次拦截后高度不会再升高,给出导弹的序列,问最多能拦截多少枚导弹? 最长递减子序列问题. #include <cstdio> #include ...
- 别人整理的DP大全(转)
动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
随机推荐
- perl5 附录一 函数集(未定稿)
附录一 函数集(未定稿) by flamephoenix 一.进程处理函数 1.进程启动函数 2.进程终止函数 3.进程控制函数 4.其它控制函数二.数学函数三.字符串处理函数四.标量转换函数 ...
- C语言实验——一元二次方程Ⅱ
C语言实验--一元二次方程Ⅱ Time Limit: 1 Sec Memory Limit: 64 MB Submit: 169 Solved: 131 [Submit][Status][Web ...
- mac下配置cocos2d-x3.0
今天看到3.0的正式版公布了,就马上荡下来试试3.0,以下记录下环境变量配置过程 打开用户文件夹下.bash_profile文件,配置环境 1.首先配置下android sdk,我的是在opt文件夹下 ...
- JavaScript编程风格--基本的格式化
缩进层级 推荐4个空格字符作为一个缩进层级. 语句结尾 推荐不要省略分号. 行的长度 最好一行不超过80个字符. 换行 在运算符后换行,下一行增加两个层级的缩进. ...
- 你能相信吗?这些都是由一个DIV元素实现的动画,纯CSS3技术
http://www.webhek.com/misc/css-loaders
- BlokUI的使用
1.点击弹出层以外的区域关闭弹出层 $(document).ready(function() { $('#demo9').click(function() { $.blockU ...
- 使用RadioGroup与RadioButton实现多选一
RadioGroup是RadioButton的集合, RadioGroup里面可以包含很多RadioButton,提供多选一机制,只能选择其中一个 RadioGroup的orientation(方向) ...
- BZOJ 1692: [Usaco2007 Dec]队列变换( 贪心 )
数据 n <= 30000 , 然后 O( n² ) 的贪心也过了..... USACO 数据是有多弱啊 = = ( ps : BZOJ 1640 和此题一模一样 , 双倍经验 ) ------ ...
- D1-Linux-CentOS学习打卡
从一月底开始萌生了想在继续学Python的时候,学一门新的操作系统. 在看很多程序员的JD时,很多都要求熟悉LINUX,并且奔方法里面也提到了在LINUX下的编程. ----------------- ...
- A package manager for Qt
官网 http://www.qpm.io/ A package manager for Qt 注释:这个网站类似JavaScript的包管理器的网站https://www.npmjs.com/ 都是给 ...