POJ 1631 Bridging signals
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 9441 | Accepted: 5166 |
Description

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 specifies 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
Output
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
题目大意:最大上升子序列。
解题方法:此题数据量较大,如果采用DP的话,那么时间复杂度太大,肯定超时,在这里必须采用二分法。
#include <stdio.h> int main()
{
int nCase, num[], Stack[], ans = , low, high, mid, n;
scanf("%d", &nCase);
while(nCase--)
{
scanf("%d", &n);
for (int i = ; i < n; i++)
{
scanf("%d", &num[i]);
}
Stack[] = num[];
ans = ;
for (int i = ; i < n; i++)
{
low = ;
high = ans;
while(low <= high)
{
mid = (low + high) / ;
if (num[i] < Stack[mid])
{
high = mid - ;
}
else
{
low = mid + ;
}
}
Stack[low] = num[i];
ans = low > ans ? low : ans;
}
printf("%d\n", ans);
}
return ;
}
POJ 1631 Bridging signals的更多相关文章
- OpenJudge/Poj 1631 Bridging signals
1.链接地址: http://poj.org/problem?id=1631 http://bailian.openjudge.cn/practice/1631 2.题目: Bridging sign ...
- poj 1631 Bridging signals (二分||DP||最长递增子序列)
Bridging signals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9234 Accepted: 5037 ...
- POJ 1631 Bridging signals(LIS O(nlogn)算法)
Bridging signals Description 'Oh no, they've done it again', cries the chief designer at the Waferla ...
- POJ 1631 Bridging signals(LIS 二分法 高速方法)
Language: Default Bridging signals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1076 ...
- POJ 1631 Bridging signals & 2533 Longest Ordered Subsequence
两个都是最长上升子序列,所以就放一起了 1631 因为长度为40000,所以要用O(nlogn)的算法,其实就是另用一个数组c来存储当前最长子序列每一位的最小值,然后二分查找当前值在其中的位置:如果当 ...
- 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的所有最长上升子序列中的最小序 ...
- Poj 1631 Bridging signals(二分+DP 解 LIS)
题意:题目很难懂,题意很简单,求最长递增子序列LIS. 分析:本题的最大数据40000,多个case.用基础的O(N^2)动态规划求解是超时,采用O(n*log2n)的二分查找加速的改进型DP后AC了 ...
- POJ 1631 Bridging signals(LIS的等价表述)
把左边固定,看右边,要求线不相交,编号满足单调性,其实是LIS的等价表述. (如果编号是乱的也可以把它有序化就像Uva 10635 Prince and Princess那样 O(nlogn) #in ...
随机推荐
- Msbuild利用cpu多核加速
msbuild /t:Rebuild /p:Configuration=Release /m /m 自动检测cpu数量启动对应数量进程
- JavaScript 火的有点过头了,但又能火多久呢?
2016年的前端是遍地开花的一年,各种前端框架,各种库,学都学不完,反正在前端的世界里,没有什么是JavaScript实现不了的... JavaScript 你还能再火几年?? 前些年node被捧上天 ...
- windows下python检查文件是否被其它文件打开.md
有时候我们需要能够判断一个文件是否正在被其它文件访问,几乎不可避免的要调用操作系统接口 from ctypes import cdll import os _sopen = cdll.msvcrt._ ...
- 【仅支持移动设备】Swipe.JS轻量级移动幻灯效果
在线演示 本地下载 请使用手机直接访问地址: 单独页面展示效果
- [Java拾遗二]Tomact及Http 部分总结.
前言: 刚好今天回来的很早, 总结下 Tomcat及Http的基础知识. 1, Tomcat web相关概念 web:网页的意思,网页资源包括服务器上的所有资源. ...
- paip.java swt 乱码问题解决
paip.java swt 乱码问题解决 看累挂,Dfile.encoding是gbk的.. 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专 ...
- React组件系统、props与状态(state)
多个组件合成一个组件: var style = { fontSize: 20, color: '#ff0000' }; var WebSite = React.createClass({ rende ...
- C语言内存分布之数据段
不管我们以后是自己写代码还是读别人的代码,都应该想想这个变量默认存储的位置.在我们以后的嵌入式开发中,技巧性的代码越来越多的时候,我们可能把某一些代码放在一段.我们可以通过修改变量或者代码默认放置的段 ...
- jQuery单选框radio绑定click事件
<div class="con_head"> <label><input type="radio" name="ask& ...
- nginx 负载均衡集群解决方案 healthcheck_nginx_upstreams (一)
该文章来源于互联网,目前找不到原作者,放在这里的目的是记录healthcheck_nginx_upstreams 的安装过程和相关配置,在起初安装成功后不能够正常运行healthcheck_nginx ...