poj 1887 Testing the CATCHER_最长上升子序列
题意:题目太长没看,直接看输入输出猜出是最长下降子序列
用了以前的代码直接a了,做法类似贪心,把最小的顺序数存在数组里面,每次二分更新数组得出最长上升子序列
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int dp[40002],a[40002],n,t,i,low,up,top,mid,max,tmp,k,b[40002],cas=1;
while(1)
{
scanf("%d",&tmp);
if(tmp==-1)
break;
k=1;
b[k++]=tmp;
while(scanf("%d",&tmp)){
if(tmp==-1)
break;
b[k++]=tmp; }
k--;
for(i=1;i<=k;i++)
a[i]=b[k-i+1];
top=1;
dp[1]=a[1];
max=0;
for(i=1;i<=k;i++)
{
low=1;
up=top;
while(low<=up)
{
mid=(low+up)/2;
if(dp[mid]>=a[i])
up=mid-1;
else
low=mid+1;
}
dp[low]=a[i];
if(low>top)
top++;
}
printf("Test #%d:\n",cas++);
printf(" maximum possible interceptions: %d\n\n",top);
}
return 0;
}
poj 1887 Testing the CATCHER_最长上升子序列的更多相关文章
- POJ 1887 Testingthe CATCHER (LIS:最长下降子序列)
POJ 1887Testingthe CATCHER (LIS:最长下降子序列) http://poj.org/problem?id=3903 题意: 给你一个长度为n (n<=200000) ...
- poj 2533 Longest Ordered Subsequence 最长递增子序列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...
- 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)
一.Description A military contractor for the Department of Defense has just completed a series of pre ...
- POJ 2533 - Longest Ordered Subsequence - [最长递增子序列长度][LIS问题]
题目链接:http://poj.org/problem?id=2533 Time Limit: 2000MS Memory Limit: 65536K Description A numeric se ...
- {POJ}{3903}{Stock Exchange}{nlogn 最长上升子序列}
题意:求最长上升子序列,n=100000 思路:O(N^2)铁定超时啊....利用贪心的思想去找答案.利用栈,每次输入数据检查栈,二分查找替换掉最小比他大的数据,这样得到的栈就是更优的.这个题目确实不 ...
- poj 3903 Stock Exchange(最长上升子序列,模版题)
题目 #include<stdio.h> //最长上升子序列 nlogn //入口参数:数组名+数组长度,类型不限,结构体类型可以通过重载运算符实现 //数组下标从1号开始. int bs ...
- POJ 1631 Bridging signals DP(最长上升子序列)
最近一直在做<挑战程序设计竞赛>的练习题,感觉好多经典的题,都值得记录. 题意:给你t组数据,每组数组有n个数字,求每组的最长上升子序列的长度. 思路:由于n最大为40000,所以n*n的 ...
- POJ 1631 Bridging signals (LIS:最长上升子序列)
题意:给你一个长为n(n<=40000)的整数序列, 要你求出该序列的最长上升子序列LIS. 思路:要求(nlogn)解法 令g[i]==x表示当前遍历到的长度为i的所有最长上升子序列中的最小序 ...
随机推荐
- java生成json字符串的方法
例1:将map对象添加一次元素(包括字符串对.数组),转换成json对象一次. 代码: package com.json; //这是使用org.json的程序: import java.util.Ha ...
- Linux系统编程(24)——信号的生命周期
信号生命周期为从信号发送到信号处理函数的执行完毕. 对于一个完整的信号生命周期(从信号发送到相应的处理函数执行完毕)来说,可以分为三个重要的阶段,这三个阶段由四个重要事件来刻画:信号诞生:信号在进程中 ...
- bzoj1630 [Usaco2007 Demo]Ant Counting
Description Bessie was poking around the ant hill one day watching the ants march to and fro while g ...
- Word Ladder 解答
Question Given two words (beginWord and endWord), and a dictionary's word list, find the length of s ...
- Longest Substring Without Repeating Characters 解答
Question Given a string, find the length of the longest substring without repeating characters. For ...
- cc150 Chapter 2 | Linked Lists 2.5 add two integer LinkedList, return LinkedList as a sum
2.5 You have two numbers represented by a linked list, where each node contains a single digit. The ...
- find命令笔记
find 命令: 文件查找:locate: 非实时,模糊匹配,查找是根据全系统文件数据库进行的:# updatedb, 手动生成文件数据库速度快 find: 实时 精确 支持众 ...
- hdu 5631 Rikka with Graph(图)
n个点最少要n-1条边才能连通,可以删除一条边,最多删除2条边,然后枚举删除的1条边或2条边,用并查集判断是否连通,时间复杂度为O(n^3) 这边犯了个错误, for(int i=0;i<N;i ...
- Qemu之Network Device全虚拟方案三: I/O虚拟化
前面两文主要对前端网络流的数据路径和虚拟网卡的创建进行了说明,这些能够看做是Guest OS网络数据包收发的准备工作,那么网络数据包是怎样在Guest OS中进进出出的呢,本文就是重点讲述Guest ...
- 解决 jsp:include 引用文件时出现乱码的问题
阐述问题前,先来看一下下面这张图片左侧iframe中的乱码页面: 这个就是让我纠结好一阵子的乱码截图: 这个乱码页面中是使用了<jsp:include>引用标签后出现了这个问题: 源码截图 ...