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 ...
随机推荐
- C++的二进制兼容问题(以QT为例)
二进制不兼容带来的问题(需要重新编译库文件,以前编译的失效): http://my.oschina.net/lieefu/blog/505363?fromerr=f5jn7rct 二进制不兼容的原理: ...
- Java并发编程总结2——慎用CAS(转)
一.CAS和synchronized适用场景 1.对于资源竞争较少的情况,使用synchronized同步锁进行线程阻塞和唤醒切换以及用户态内核态间的切换操作额外浪费消耗cpu资源:而CAS基于硬件实 ...
- spring学习总结(mybatis,事务,测试JUnit4,日志log4j&slf4j,定时任务quartz&spring-task,jetty,Restful-jersey等)
在实战中学习,模仿博客园的部分功能.包括用户的注册,登陆:发表新随笔,阅读随笔:发表评论,以及定时任务等.Entity层设计3张表,分别为user表(用户),essay表(随笔)以及comment表( ...
- python开发_大小写转换,首字母大写,去除特殊字符
这篇blog主要是总结我们在平常开发过程中对字符串的一些操作: #字母大小写转换 #首字母转大写 #去除字符串中特殊字符(如:'_','.',',',';'),然后再把去除后的字符串连接起来 #去除' ...
- QQ聊天原理初识
1:qq之间文件的传输是通过p2p通信进行的. 2:qq之间的表情发送实际上就是文字的发送,是client再接受到文字之后在本地自己进行转换 3:qq之间的通信既能够通过udp也能够通过Tcp 尽管u ...
- Java之旅(一)---说说“异常”那些事
从開始学习VB,就听说过"异常",认为异常处理就是加上try..catch,不让错误抛出给用户,到此为止,不要再往下问了,再问也不会了.这就是那时候的理解.如今随时项目经验的 ...
- Json在asp.net开发中的应用
一.asp.net后台返回Json数据,前台js解析 在后台读取数据,并手动封装成Json格式: public ContentResult getUsersByOrgId(int Id) { Data ...
- c 计算Fibonacci数列:1,1,2,3,5,8,13……这题也是很经典。
输出数字序列2/,/,/,/,/,/...,输出个数由键盘输入.注意输入使用scanf输入 比如: 输入 3输出为 / / / 输入 输出为 / / / / #include<stdio.h&g ...
- 理解SQL SERVER中的分区表
转自:http://www.cnblogs.com/sienpower/archive/2011/12/31/2308741.html 简介 分区表是在SQL SERVER2005之后的版本引入的特性 ...
- Java多线程之synchronized(三)
在多线程访问同一个对象中的不同的synchronized方法或synchronized代码块的前提下,也就是“对象监控器”为同一个对象的时候,也就是synchronized的锁为同一把锁的时候,调用的 ...