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 ...
随机推荐
- Richview 首页 奇偶页 不同页眉页脚
首页 奇偶页 不同页眉页脚 ScaleRichView v6.0 Different headers and footers for the first page, for odd and even ...
- 横向文本框 index获取索引 和 eq 实现
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 横向文本框 cursor:pointer 出现手型
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Redis 哨兵模式 带密码单机
语法 https://segmentfault.com/a/1190000002680804 启动3台redis 6379,6380,6381 cp 多个redis.conf文件 开启daemoniz ...
- 光圈、曝光、ISO
光圈大小对景深的影响: 光圈大小示意图(值越小光圈越大) 光圈.曝光.ISO对图像效果影响
- Symfony 建立一个Bundle
如果说,这个时候你萌生了一个去看一看Symfony源码的想法,个人建议还是算了,看了之后,你就会感到非常迷茫.因为他实在是大于绝大部分你使用过的框架,并且有多达近二十个的插件,使用了一些非常精巧的设计 ...
- 创建maven版的java工程
步骤如下: 1.第一步 2.第二步: 3.第三步:
- servlet访问路径的写法
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://w ...
- XML解析的二种方法之dom解析
XML解析的二种方法:dom解析和sax解析 文件大小 存储位置 读取速度 dom解析 小文件 放在内存中 快 sax解析 ...
- Python any() 函数
Python any() 函数 Python 内置函数 描述 any() 函数用于判断给定的可迭代参数 iterable 是否全部为 False,则返回 False,如果有一个为 True,则返回 ...