OpenJudge/Poj 1631 Bridging signals
1.链接地址:
http://poj.org/problem?id=1631
http://bailian.openjudge.cn/practice/1631
2.题目:
Bridging signals
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9882 Accepted: 5409 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 crossing each other, is imminent. Bearing in mind that there may be thousands 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?
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
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
6Sample Output
3
9
1
4Source
3.思路:
4.代码:
#include "stdio.h"
//#include "stdlib.h"
#define NUM 40002
int dp[NUM];
int c[NUM];
int a[NUM];
int bsearch(int c[],int n,int a)
{
int l = ,r = n;
int m;
while(l<=r)
{
m=(l+r)/;
if(a>c[m] && a<=c[m+]) return m+;
else if(a<c[m]) r=m-;
else l=m+;
}
}
int LIS(int a[],int n)
{
int i,j,size=;
dp[]=;c[]=a[];
for(i=;i<=n;i++)
{
if(a[i] <= c[]) j=;
else if(a[i] > c[size]) j=++size;
else j= bsearch(c,size,a[i]);
c[j]=a[i];dp[j];
}
return size;
}
int main()
{
int n,p;
int i,j;
int ans;
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%d",&p);
for(j=;j<=p;j++) scanf("%d",&a[j]);
int ans = LIS(a,p);
printf("%d\n",ans);
}
//system("pause");
return ;
}
OpenJudge/Poj 1631 Bridging signals的更多相关文章
- POJ 1631 Bridging signals
Bridging signals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9441 Accepted: 5166 ...
- 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 ...
随机推荐
- HTTP/2 常见问题回答
常见问题 为什么修订HTTP? HTTP/1.1已经很好的服务Web超过15个年头,但它的劣势开始显现. 载入一个Web页面比之前占用更多的资源(详情可见HTTP压缩页大小统计),有效的载入这些资源很 ...
- Redis在PHP中的基本使用案例
下载http://www.oschina.net/p/redis 解压后里面有:lib 源文件 .examples 例子.test测试 将lib目录拷贝到你的项目中,就可以开始你的predis操作了. ...
- IE-首页跳转到 q160的问题解决
IE首页跳转到 q160的问题解决 服了又中找了,IE快捷方式被 www.q160.com劫持 该死的这个网站什么也没有做,就是做了一个google搜索的连接. 进行了一次搜索 http: ...
- 问题-RZ安装后报错“RzBorder.pas”
错误象现:[Error] RzBorder.pas(1429): Number of elements differs from declaration [Fatal Error] RzEdit.pa ...
- JS跨域笔记
什么是跨域,跨域是指不同域之间相互访问,只要协议.域名.端口有任何一个不同,都被当作是不同的域. 对于端口和协议的不同,只能通过后台来解决,前台是无能为力的. 受浏览器同源策略的限制,本域的js不能操 ...
- opencv数据结构-MAT结构详解
1.定义 OpenCV中的C结构体有 CvMat 和 CvMatND,但后续的应用中指出 CvMat 和 CvMatND 弃用了,在C++封装中用 Mat 代替,另外旧版还有一个 IplImage,同 ...
- DoctorNote医生处方笔记开发记录
1.开发背景 一个开诊所的中医朋友,希望我能给他开发一个记录病人姓名和处方的Android手机app,以便查询病人每次就诊信息,比如上一次的处方,以前他要找个病人上一次的就诊处方,几乎要翻遍一叠厚厚的 ...
- Visual C++中的编译器优化
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:Visual C++中的编译器优化.
- 安卓开发20:动画之Animation 详细使用-主要通过java代码实现动画效果
AlphaAnimation 透明效果实现: activity_main.xml中仅仅是一个简单的图片,下面的例子都会使用这个xml: <RelativeLayout xmlns:android ...
- ios 解决有关火星坐标的问题
CLLocationManager 定位获取CLLocation 是地球坐标,而MKMapView 获取的是天朝火星坐标,这就导致了使用定位的时候,显示用户的蓝点和当前定位信息偏差(因为蓝点是调用了M ...
