poj1631 Bridging signals
来源:互联网 发布:天国王朝知乎 编辑:程序博客网 时间:2024/06/01 07:40
Bridging signals
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 14087 Accepted: 7619
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 crossing each other, is imminent. Bearing in mind that there may be thousands 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?
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 specifies 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.
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 specifies 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
4642631510234567891018876543219589231746
Sample Output
3914
题意就是给你n个棍子,然后每个左端的棍子都会给你相连接的右端的棍子的编号。问你去掉一些棍子,在剩下的棍子不相交的前提下使得剩余的数量最大。
我们想一下相交的情况,就是一个X,这种情况出现在两个棍子的左右端点的上下位置是交叉的。因为题目中给出的是按照左端点从1到n的,所以,我们应当找出一个上升的序列,因为要求数量最大,所以是求一个最长上升子序列,这里n2的做法显然不行,要用,nlogn的方法。这里是利用了二分的方法。
#include <cstdio>#include <cstring>#include <map>#include <algorithm>using namespace std;const int MAXN=80000+7;int num[MAXN],ans[MAXN];int n,m,k;int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=0;i<n;++i) { scanf("%d",&num[i]); } int top=0; ans[top++]=num[0]; for(int i=1;i<n;++i) { if(num[i]>=ans[top-1])ans[top++]=num[i]; else ans[lower_bound(ans,ans+top,num[i])-ans]=num[i]; } printf("%d\n",top); } return 0;}
1 0
- poj1631 Bridging signals
- POJ1631 Bridging signals
- POJ1631 Bridging signals
- poj1631 Bridging signals
- Bridging signals||POJ1631
- poj1631——Bridging signals
- DP.單調隊列::poj1631 Bridging signals
- Bridging signals ZOJ 3627 POJ1631 HDU1950
- POJ1631 Bridging signals 最长上升子序列
- POJ1631 Bridging signals(最大上升子序列)
- POJ1631——Bridging signals(动态规划)
- POJ1631-Bridging signals-最长上升子序列
- poj1631 Bridging signals(同51Nod1134)
- POJ1631 Bridging signals(DP类似最长子序列)
- poj1631 Bridging signals 加强版最长上升子序列
- ZOJ3627 POJ1631 HDU1950 Bridging Signals,O(N*logN)版最长上升子序列问题
- POJ1631——Bridging signals(动态规划,最长上升子序列应用)
- 挑战练习题2.3动态规划 poj1631 Bridging signals 最长递增子序列
- poj 3863 Business Center
- JZOJ1268.【USACO题库】2.3.3 Zero Sum和为零
- Vicarious说,现在的深度学习都是渣渣--转自微信
- Android Studio 技巧之【Join Lines and Literals】
- vim 快捷键
- poj1631 Bridging signals
- hdu1097 A hard puzzle
- hdu 1166 敌兵布阵
- Ubuntu下载android源码
- HDU4716-A Computer Graphics Problem
- 有序数组查找第一个比k大的数
- iOS程序员的持续学习
- 用户登录只有第一条数据成功,只能查询到第一条数据
- B1049.数列的片段和