杭电1950 Bridging signals(求一个数列的最大递增子数列)
来源:互联网 发布:减肥变速跑和慢跑知乎 编辑:程序博客网 时间:2024/06/06 16:31
Bridging signals
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1068 Accepted Submission(s): 694
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
转载纯真博客:二分查找(二分检索):
一个数组number序列为:4,10,11,30,69,70,96,100.设要插入数字3,9,111.pos为要插入的位置的下标
则
pos = lower_bound( number, number + 8, 3) - number,pos = 0.即number数组的下标为0的位置。
pos = lower_bound( number, number + 8, 9) - number, pos = 1,即number数组的下标为1的位置(即10所在的位置)。
pos = lower_bound( number, number + 8, 111) - number, pos = 8,即number数组的下标为8的位置(但下标上限为7,所以返回最后一个元素的下一个元素)。
所以,要记住:函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回大于或等于val的第一个元素位置。如果所有元素都小于val,则返回last的位置,且last的位置是越界的!!~
返回查找元素的第一个可安插位置,也就是“元素值>=查找值”的第一个元素的位置
upper_bound():
头文件:#include<algorithm>
函数模板: 如binary_search()
函数功能:函数upper_bound()返回的在前闭后开区间查找的关键字的上界,返回大于val的第一个元素位置
例如:一个数组number序列1,2,2,4.upper_bound(2)后,返回的位置是3(下标)也就是4所在的位置,同样,如果插入元素大于数组中全部元素,返回的是last。(注意:数组下标越界)
返回查找元素的最后一个可安插位置,也就是“元素值>查找值”的第一个元素的位置
注意:
然后_rows.insert( iter, 4);这句将按照从小到大的顺序将4放进去,最后的顺序是{0,1,3,4,5}
#include<stdio.h>#include<algorithm>using namespace std;int a[40000];int main(){int n,i,m,b,top,postion;scanf("%d",&n);while(n--){top=0;scanf("%d",&m);scanf("%d",&a[0]);for(i=1;i<m;i++){scanf("%d",&b);if(b>a[top]){top++;a[top]=b;}else{postion=lower_bound(a,a+top,b)-a;//返回第一次出现大于等于b的数的下标 a[postion]=b;}}printf("%d\n",top+1);//因为第一个数的下标为0,所以top要加1;}return 0;}
- 杭电1950 Bridging signals(求一个数列的最大递增子数列)
- hdu杭电1950 Bridging signals【最大递增子序列(不连续)】
- 杭电1950 Bridging signals(二分求最长上升子序列)
- 最大递增子数列
- 2.16 求一个数列的最长递增子序列
- 求数列的最长递增子序列
- 杭电-1950Bridging signals(LIS)
- 杭电1950Bridging signals
- 杭电1950Bridging signals
- 求一个数列中的最大子序列
- 在数组中,寻找一个最大递增子数列
- 求最大子数列的和
- poj 1631 Bridging signals(最长递增子序列)
- poj 1631Bridging signals Dp(最长递增子序列)
- hdu1950 Bridging signals(最长递增子序列二分)
- 【 HDU 杭电 1950 Bridging signals】
- HDU 1950 Bridging signals (最长递增子序列(nlogn算法)
- 杭电2009 求数列的和
- super和this的用法
- 如何修改sublime3代码注释颜色
- [BZOJ1047][HAOI2007]理想的正方形
- BGP的13条选路原则
- 2015 多校联赛 ——HDU5294(最短路,最小切割)
- 杭电1950 Bridging signals(求一个数列的最大递增子数列)
- 记录Uniyt3d Shader的几个用法
- UNIX 系统家族树的详细历史(图)
- mysql 生成流水号每天更新从0开始
- PAT (Advanced Level) 1087. All Roads Lead to Rome (30) 条条大路通罗马 Dijkstra+DFS
- 读书笔记MoreEffectiveC++(34)
- [BZOJ1054][HAOI2008]移动玩具
- nyoj 214 单调递增子序列(二) 【LIS】
- HDU 5327 区间里由不同的数字组成的数的个数-set-(枚举)