Bridging signals

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4452    Accepted Submission(s): 2769

Problem Description
'Oh
no, they've done it again', cries the chief designer at the Waferland
chip factory. Once more the routing designers have screwed up
completely, making the signals on the chip connecting the ports of two
functional blocks cross each other all over the place. At this late
stage of the process, it is too
expensive to redo the routing.
Instead, the engineers have to bridge the signals, using the third
dimension, so that no two signals cross. However, bridging is a
complicated operation, and thus it is desirable to bridge as few
signals as possible. The call for a computer program that finds the
maximum number of signals which may be connected on the silicon surface
without rossing each other, is imminent. Bearing in mind that there may
be housands of signal ports at the boundary of a functional block, the
problem asks quite a lot of the programmer. Are you up to the task?

Figure
1. To the left: The two blocks' ports and their signal mapping
(4,2,6,3,1,5). To the right: At most three signals may be routed on the
silicon surface without crossing each other. The dashed signals must be
bridged.

A typical situation is schematically depicted in figure
1. The ports of the two functional blocks are numbered from 1 to p,
from top to bottom. The signal mapping is described by a permutation of
the numbers 1 to p in the form of a list of p unique numbers in the
range 1 to p, in which the i:th number pecifies which port on the right
side should be connected to the i:th port on the left side.
Two signals cross if and only if the straight lines connecting the two ports of each pair do.

 
Input
On
the first line of the input, there is a single positive integer n,
telling the number of test scenarios to follow. Each test scenario
begins with a line containing a single positive integer p<40000, the
number of ports on the two functional blocks. Then follow p lines,
describing the signal mapping: On the i:th line is the port number of
the block on the right side which should be connected to the i:th port
of the block on the left side.
 
Output
For
each test scenario, output one line containing the maximum number of
signals which may be routed on the silicon surface without crossing each
other.
 
Sample Input
4
6
4 2 6 3 1 5
10
2 3 4 5 6 7 8 9 10 1
8
8 7 6 5 4 3 2 1
9
5 8 9 2 3 1 7 4 6

Sample Output

3
9
1
4
#include<iostream>
#include<algorithm>
using namespace std;
int a[],lis[];
int t,n;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
for(int i=;i<=n;i++)//因为upper_bound(),所以从1开始方便
{
cin>>a[i];
}
int len=;
for(int i=;i<=n;i++)
{
if(a[i]>lis[len])//严格单调
{
lis[++len]=a[i];
continue;
}
int t=upper_bound(lis,lis+len,a[i])-lis;//返回第一个比a[i]大的数
lis[t]=a[i];
}
cout<<len<<endl;
} return ;
}

hdu 1950 Bridging signals 求最长子序列 ( 二分模板 )的更多相关文章

  1. HDU 1950 Bridging signals【最长上升序列】

    解题思路:题目给出的描述就是一种求最长上升子序列的方法 将该列数an与其按升序排好序后的an'求出最长公共子序列就是最长上升子序列 但是这道题用这种方法是会超时的,用滚动数组优化也超时, 下面是网上找 ...

  2. HDU 1950 Bridging signals (DP)

    职务地址:HDU 1950 这题是求最长上升序列,可是普通的最长上升序列求法时间复杂度是O(n*n).显然会超时.于是便学了一种O(n*logn)的方法.也非常好理解. 感觉还用到了一点贪心的思想. ...

  3. HDU 1950 Bridging signals(LIS)

    最长上升子序列(LIS)的典型变形,O(n^2)的动归会超时.LIS问题可以优化为nlogn的算法. 定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元 ...

  4. HDU 1950 Bridging signals (LIS,O(nlogn))

    题意: 给一个数字序列,要求找到LIS,输出其长度. 思路: 扫一遍+二分,复杂度O(nlogn),空间复杂度O(n). 具体方法:增加一个数组,用d[i]表示长度为 i 的递增子序列的最后一个元素, ...

  5. HDU 1950 Bridging signals

    那么一大篇的题目描述还真是吓人. 仔细一读其实就是一个LIS,还无任何变形. 刚刚学会了个二分优化的DP,1A无压力. //#define LOCAL #include <iostream> ...

  6. 求最长子序列(非连续)的STL方法 - 洛谷P1020 [NOIP1999 普及组] 导弹拦截

    先给出例题:P1020 [NOIP1999 普及组] 导弹拦截 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 大佬题解:P1020 [NOIP1999 普及组] 导弹拦截 - 洛谷 ...

  7. hdoj 1950 Bridging signals【二分求最大上升子序列长度】【LIS】

    Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. (hdu)1950 Bridging signals(最长上升子序列)

    Problem Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip f ...

  9. HDU 6625 three arrays 求两个序列异或最小值的排列(一个可以推广的正解

    目录 题意: 解析 原题描述 字典树动态求Mex @(hdu 6625求两个序列异或最小值的排列) 题意: \(T(100)\)组,每组两个长度为\(n(100000)\)的排列,你可以将\(a[]\ ...

随机推荐

  1. pip升级报错(权限问题)

    今天跟新pip的时候错一个接一个 看到拒绝访问应该是权限的问题,想起安装的时候选择谁可以使用软件(大概是这样的一个选项),选择了“只有我”,选择所有用户应该就不会存在这个问题了,那么怎么解决呢? 敲黑 ...

  2. COGS 2294. [HZOI 2015] 释迦

    额,其实就是裸的三模数NTT,上一篇已经说过了 哦,还有一个就是对乘起来炸long long的数取模,用long double之类的搞一下就好,精度什么的,,(看出题人心情??) #include&l ...

  3. Python—网络通信编程之udp通信编程

    服务端代码 import socket # 1.创建实例,即数据报套接字 server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # 2.绑 ...

  4. 080、Java数组之二维数组的定义及使用

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  5. acid-事务的原子性、一致性、隔离性、持久性

    博客分类: oracle-dba   原子性  多个事情组成一个单元,要么同时成功或失败,不能只运行其中一个 一致性  事务处理要将数据库从一种状态转变为另一种状态. 一旦提交了修改数据,那么其它人读 ...

  6. JuJu团队12月28号工作汇报

    JuJu团队12月28号工作汇报 JuJu   Scrum 团队成员 今日工作 剩余任务 困难 飞飞 完成GUI 待安排 无 婷婷 调试代码 提升acc 无 恩升 修正evaluate 修正evalu ...

  7. 在Anaconda3环境下安装并切换 Tensorflow 2.0 环境

    背景 Anaconda切换各种环境非常方便,现在我们就来介绍一下如何使用anaconda安装tensorflow环境. anaconda v3.5 from 清华镜像站 tensorflow v2.0 ...

  8. CentOS操作系统部署zabbix agent服务

    CentOS操作系统部署zabbix agent服务 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查看zabbix的官方手册 1>.点击下载 2>.查看Ubunt ...

  9. C语言整理复习——指针

    指针是C的精华,不会指针就等于没学C.但指针又是C里最难理解的部分,所以特意写下这篇博客整理思路. 一.指针类型的声明 C的数据类型由整型.浮点型.字符型.布尔型.指针这几部分构成.前四种类型比较好理 ...

  10. 怎样设置使IntelliJ IDEA智能提示忽略大小写?

    打开设置(CTRL+ALT+S)打开editor,找到“Code Completion”->点击Match case前面的框不勾选即可.如下图: