Click to open link
Bridging signals
| Time Limit: 1000MS |
|
Memory Limit: 10000K |
| Total Submissions: 10951 |
|
Accepted: 6000 |
Description
' Oh no, they ' ve do it again ', cries the chief designer at the Waferland chip factory. Once more The routing designers has screwed up completely, making the signals on the chip connecting the ports of the Ctional blocks cross each of the other and the place. At this late stage of the process, it's too expensive to redo the routing. Instead, the engineers has to bridge the signals, using the third dimension, so, no, and cross signals. However, bridging is a complicated operation, and thus it's desirable to bridge as few signals as possible. The call for a computer program This finds the maximum number of signals which may is connected on the silicon surface wit Hout crossing each and imminent. Bearing in mind that there is thousands of signal ports at the boundary of a functional block, the problem asks quite A lot of the programmer. Is you up to the task?
A Typical situation is schematically depicted in Figure 1. The ports of the functional blocks is numbered from 1 to p and 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 RA Nge 1 to P, in which the i:th number specifies which ports on the right side should is connected to the i:th port on the Le FT side. The signals cross if and only if the straight lines connecting the both ports of each pair do.
Input
On the first line of the input, there are a single positive integer n, telling the number of the test scenarios to follow. Each test scenario begins with a line containing a single positive integers p < 40000, the number of ports on the and the FU Nctional blocks. Then follow P lines, describing the signal mapping:on the i:th line is the port number of the "The Block on the" right side whic H should is connected to the i:th port of the 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 SURFAC e without crossing each other.
Sample Input
4642631510234567891018876543219589231746
Sample Output
3914
Title translation: What is the title of the translation is not important, the first data T represents the T Group of data, and then each group of data has an n, followed by n numbers, respectively, is the 1-n of the disorder of the sequence, and then find the longest ascending subsequence sequence.
Solution thinking: With the violence to solve the time-out, so in the search for insertion using 2-point method, easy to solve the problem.
#include <stdio.h>int a[40000],t,n,num,res,i,w;int Q (int left,int right,int path) { int mid; while (left<=right) { mid= (left+right)/2; if (A[mid]<path) left=mid+1; else right=mid-1; } return right;} int main () { scanf ("%d", &t); while (t--) { scanf ("%d", &n); scanf ("%d", &num); A[0]=num; Res=1; for (i=1;i<n;i++) { scanf ("%d", &num); if (num>a[res-1]) a[res++]=num; else if (Num<a[res-1]) { w=q (0,res-1,num); A[w+1]=num; } } printf ("%d\n", res); } return 0;}
God-General STL
#include <stdio.h> #include <algorithm>using namespace Std;int a[40000],t,n,num,res,i,w;int main () { scanf ("%d", &t); while (t--) { scanf ("%d", &n); scanf ("%d", &num); A[0]=num; Res=1; for (i=1;i<n;i++) { scanf ("%d", &num); if (num>a[res-1]) a[res++]=num; else if (Num<a[res-1]) { w=lower_bound (a,a+res,num)-A; A[w]=num; } } printf ("%d\n", res); } return 0;}
STL's simplest version
#include <stdio.h> #include <algorithm>using namespace Std;int a[40000],t,n,num,i,k,size;int main () { scanf ("%d", &t); while (t--) { scanf ("%d", &n); for (i=0,size=0;i<n;i++) { scanf ("%d", &num); K=lower_bound (A,a+size,num)-A; A[k]=num; Size=max (size,k+1); } printf ("%d\n", size); } return 0;}
POJ 1631 bridging signals