Bridging signals

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2354    Accepted Submission(s): 1536

Problem Description
'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.

 
Input
On the first line of the input, there is a single positive integer n, telling the number of test scenarios to follow. Each test scenario begins with a line containing a single positive integer p<40000, the number of ports on the two functional 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.
 
Output
For each test scenario, output one line containing the maximum number of signals which may be routed on the silicon surface without crossing each other.
 
Sample Input
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
 
Sample Output
3
9
1
4
 
Source

/*----------------------------------------------
File: F:\ACM源代码\动态规划\最长上升子序列\HDU1950.cpp
Date: 2017/5/30 10:24:29
Author: LyuCheng
----------------------------------------------*/
#include <bits/stdc++.h>
#define MAXN 40005 using namespace std; int n,t,len;
int b[MAXN],d[MAXN];
int binary_seacher(int i){
int left,right,mid;
left=,right=len;
while(left<right){
mid=left+(right-left)/;
if(b[mid]>=d[i]) right=mid;
else left=mid+;
}
return left;
}
int main(int argc, char *argv[])
{
// freopen("in.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&d[i]);
}
b[]=d[];
len=;
for(int i=;i<=n;i++){
if(b[len]<d[i]){
b[++len]=d[i];
}else{
int pos=binary_seacher(i);
b[pos]=d[i];
}
}
printf("%d\n",len);
}
return ;
}

最新文章

  1. 分享个刚写好的 android 的 ListView 动态加载类,功能全而代码少。
  2. CentOS 7.2 安装配置mysql主从服务器
  3. SqlServer性能优化 提高并发性能二(九)
  4. RSA算法小记
  5. Nodejs_day01
  6. samba服务设置,Linux系统和Windows文件共享
  7. HDU 3974 Assign the task 暴力/线段树
  8. bzoj3038 上帝造题的七分钟2
  9. IBM中枪后,下一个是谁?
  10. Arcade初探[0] 目录与导航
  11. 《Java大学教程》—第18章 高级图形编程
  12. 利用Java获取ip地址
  13. 【转】Extjs2.2.1 DateField 变形的问题解决方案
  14. CheckedListBox&#160; 数据绑定
  15. 一、jdk工具之jps(JVM Process Status Tools)命令使用
  16. robot framework学习笔记之八—解决列表或者字典中文乱码问题
  17. 深入理解java集合框架之---------LinkedList
  18. jar 解压war包到指定目录
  19. DLL DEF文件编写方法 VC++ 调用、调试DLL的方法 显式(静态)调用、隐式(动态)调用
  20. windows 2008 server 英文版 支持中文显示

热门文章

  1. 一款简单而不失强大的前端框架——【Vue.js的详细入门教程①】
  2. String类的替换方法(9)
  3. Opengl4.5 中文手册—C
  4. const的用法,特别是用在函数前面与后面的区别!
  5. java中集合的增删改操作及遍历总结
  6. Asp数据转Json
  7. Ansible(一) - 入门及安装
  8. 项目管理软件之争,禅道和JIRA大对比
  9. mysql error 1290 hy000:The MySQL server is running with the --skip-grant-tables option so it cannot execute this statemen&#39; 解决方案
  10. java中类之间的关系之封装、继承与多态的几个例子