Bridging signals
来源:互联网 发布:奥地利 知乎 编辑:程序博客网 时间:2024/06/05 22:34
点击打开链接
'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 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.
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.
4642631510234567891018876543219589231746
3914
分析:
初看题目和数据好吓人,但是细细看就发现是LIS的运用;注意:考虑时间复杂度,这里要用(nlogn)算法;
代码:
#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;int a[1000000];int dp[1000000];int len;int BinarySearch(int x){int left=1,right=len,mid;while(left<=right){mid=(left+right)/2;if(dp[mid-1]<=x&&x<dp[mid])return mid;else if(x>dp[mid])left=mid+1;else right=mid-1;}}int main(){int t;scanf("%d",&t);while(t--){int n,j;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);memset(dp,0,sizeof(dp));dp[1]=a[1]; len=1;for(int i=2;i<=n;i++){if(dp[1]>=a[i])j=1;else if(a[i]>dp[len])j=++len;else j= BinarySearch(a[i]);dp[j]=a[i];}printf("%d\n",len);}return 0;}
另一种是简化了的:
#include<cstdio>#include<algorithm>#define INF 0x3f3f3f3fusing namespace std;int a[30000+10];int dp[30000+10];int main(){int t,n;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);fill(dp,dp+n,INF);for(int i=1;i<=n;i++)*lower_bound(dp,dp+n,a[i])=a[i];printf("%d\n",lower_bound(dp,dp+n,INF)-dp);}return 0;}
阅读全文
0 0
- Bridging signals
- Bridging signals
- Bridging signals
- Bridging signals
- Bridging signals
- Bridging signals
- Bridging Signals
- Bridging signals
- Bridging signals
- Bridging signals
- Bridging signals
- Bridging signals
- pku 1631 Bridging signals
- POJ 1631 Bridging signals
- PKU的Bridging Signals
- ZOJ 1986 Bridging Signals
- Bridging signals POJ 1631
- poj1631 Bridging signals
- CSS保持长宽比
- python爬虫——从此不用再愁找不到小说txt文件
- 短信在Mms中处理流程
- 局域网中连接mysql数据库
- SQL NOT NULL 约束
- Bridging signals
- JZOJ 5132 子序列
- Wormholes(负权回路)
- 最小生成树( Highways + Agri-Net)
- Peter的烟
- A+B problem
- 2-6使用ACL访问控制列表对文件的访问
- 2017.6.4测试 题七 K上升段
- 常见的排序算法C语言实现(—)