B - Bridging signals (LIS)
B - Bridging signals
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.
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.
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
3
9
1
4
错误代码(一组数据行,怎么实现多组数据输入?)
#include <stdio.h>
#include <cstring>
#include <algorithm>
#define INF 0x3f3f3f
using namespace std;
int dp[30020],a[30020];
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int m;
scanf("%d",&m);
for(int i=0; i<m ; i++)
{
scanf("%d",&a[i]);
dp[i]=INF;
}
for(int i=0; i<m; i++)
*lower_bound(dp,dp+n,a[i])=a[i]; //优化
printf("%d\n",lower_bound(dp,dp+m,INF)-dp);
}
return 0;
}
正确代码
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std; int a[41000];
int main()
{
int N,n,i,j,t;
scanf("%d",&N);
while(N--)
{
scanf("%d",&n);
scanf("%d",&t);
a[0]=t;
int top=1;
for(i=1; i<n; i++)
{
scanf("%d",&t);
if(t>=a[top-1])
a[top++]=t;
else
{
int z=0,q=top-1;
while(z<=q)
{
int mid=(z+q)/2;
if(a[mid]<t)
z=mid+1;
else
q=mid-1;
}
a[z]=t;
}
}
printf("%d\n",top);
}
return 0;
}
B - Bridging signals (LIS)的更多相关文章
- 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(LIS的等价表述)
把左边固定,看右边,要求线不相交,编号满足单调性,其实是LIS的等价表述. (如果编号是乱的也可以把它有序化就像Uva 10635 Prince and Princess那样 O(nlogn) #in ...
- HDU 1950 Bridging signals (LIS,O(nlogn))
题意: 给一个数字序列,要求找到LIS,输出其长度. 思路: 扫一遍+二分,复杂度O(nlogn),空间复杂度O(n). 具体方法:增加一个数组,用d[i]表示长度为 i 的递增子序列的最后一个元素, ...
- ZOJ 1093 Monkey and Banana (LIS)解题报告
ZOJ 1093 Monkey and Banana (LIS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- 浅谈最长上升子序列(LIS)
一.瞎扯的内容 给一个长度为n的序列,求它的最长上升子序列(LIS) 简单的dp n=read(); ;i<=n;i++) a[i]=read(); ;i<=n;i++) ;j<i; ...
- 最长递增子序列(LIS)(转)
最长递增子序列(LIS) 本博文转自作者:Yx.Ac 文章来源:勇幸|Thinking (http://www.ahathinking.com) --- 最长递增子序列又叫做最长上升子序列 ...
- Poj 2533 Longest Ordered Subsequence(LIS)
一.Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- Poj 3903 Stock Exchange(LIS)
一.Description The world financial crisis is quite a subject. Some people are more relaxed while othe ...
随机推荐
- python 黑魔法 ---上下文管理器(contextor)
所谓上下文 计算机上下文(Context)对于我而言,一直是一个很抽象的名词.就像形而上一样,经常听见有人说,但是无法和现实认知世界相结合. 最直观的上下文,莫过于小学的语文课,经常会问联系上下文,推 ...
- Delphi Firemonkey Button ImageList
Delphi Firemonkey Button ImageList 按钮图标 在上面 界面上,选择Button,放个ImageList控件,添加图标到ImageList. 然后关联Button和Im ...
- Richview 首页 奇偶页 不同页眉页脚
首页 奇偶页 不同页眉页脚 ScaleRichView v6.0 Different headers and footers for the first page, for odd and even ...
- securecrt中使用上传下载sftp
securecrt中使用上传下载sftp SecureCRT这个工具自带了一个FTP,方便我们上传和下载,而且做的比较人性化,由于其基本命令和linux中基本命令大都相似,熟悉LINUX人能很容易 ...
- jquery ui的css设计二
上一篇见这里 本篇重点说一下其换肤功能 换肤一般是指改变控件的字体颜色,背景颜色,边框颜色,hover上去的颜色,背景图片,很少再会涉及修改其长宽,字体类型什么的. 以这个版本的CSS为观察对象,可以 ...
- idea git 操作
工作中多人使用版本控制软件协作开发,常见的应用场景归纳如下: 假设小组中有两个人,组长小张,组员小袁 场景一:小张创建项目并提交到远程Git仓库 场景二:小袁从远程Git仓库上获取项目源码 场景三:小 ...
- python's output redirect
[python's output redirect] fin = open("xx.txt", 'r'); print >>fin, "hello world ...
- python将url转换成二维码
准备环境 python生成二维码,需要依赖包qrcode和PIL(二维码的实质就是一个url.) python3安装PIL:pip install PIL python2安装PIL:pip insta ...
- php中++i 与 i++ 的区分详解
在编程时我们常会使用到i++和++i,那两者之间有什么区别呢,本教程就为大家详细介绍一下. 1.++i 的用法(以 a=++i ,i=2 为例) 先将 i 值加 1 (也就是 i=i+1 ),然后赋给 ...
- <!DOCTYPE html>的重要性!
噩梦开始的源头:之前写html或者jsp页面,从来不注意doctype的声明,也不太明白doctype的作用. 直到最近碰到了一个非常奇葩的bug:某一个页面在IE7和8,Chrome,ff等下正常, ...