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 ...
随机推荐
- LUA ipairs遍历的问题
t = { 1, 2, 3, nil, 4,} for k, v in ipairs(t) doprint(k, v)end print("------------------------- ...
- Android 建立Menu选单&&onOptionsItemSelected (转)
/** 当Menu有命令被选择时,会调用此方法 */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (i ...
- C#获取MAC地址的几种方法
首先需要用到的一些方法和类: public enum NCBCONST { NCBNAMSZ = 16, MAX_LANA = 254, NCBENUM = 0x37, NRC_GOODRET = 0 ...
- Code First 之类继承
关于Entity Framework 的code first 模式,相信大家都不陌生了.本文就来看看实体继承在 codefirst里的用法. 第一步 添加 code first 的环境 这里为了方便 ...
- RemoteExt 远程验证
public class RemoteExtAttribute : RemoteAttribute { private string _resourceKey; public RemoteExtAtt ...
- 转载:Candy? 在线性时间内求出素数与欧拉函数
转载自:http://www.cnblogs.com/candy99/p/6200660.html 2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MB ...
- iconv()错误
//转换字符编码过程中报错,数据会丢失,解决办法:设置第二个参数为gbk//IGNORE $strexport=iconv('UTF-8',"GBK",$strexport); $ ...
- Laravel Carbon 简明使用
快速切換前後日期 <?php use Carbon\Carbon; $now = Carbon::now(); echo $now; // 2015-03-26 00:36:47 $today ...
- 关于C语言中的Complex(复数类型)和imaginary(虚数类型)
关于C语言中的Complex(复数类型)和imaginary(虚数类型) 其实这里的复数complex就是数学里的复数,包含实部和虚部两个部分,比如:x=2.1+6i,下面进行详细介绍. C99 新增 ...
- 如何在Github上删除项目及某个文件
在Github上删除项目 在GitHub仓库中找到已经建立好的某个仓库,本篇文章以我的myBookCodes仓库为例,在建立的myBookCodes仓库中首先找到settings选项,如图所示: 将页 ...