Bridging signals
Time limit:5000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 961 Accepted Submission (s): 627
Problem Description ' Oh no, they ' ve done 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 is 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 rossing each and imminent. Bearing in mind that there is housands 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?
Figure 1. To the left:the, blocks ' ports and their signal mapping (4,2,6,3,1,5). To the Right:at most three signals is routed on the silicon surface without crossing. The dashed signals must be bridged.
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 pecifies which ports on the right side should is connected to the i:th port on the Lef T side.
The signals cross if and only if the straight lines connecting the both ports of each pair do.
Inputon the first line of the input, there are 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 and the Ctional 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 WHI CH should is connected to the i:th port of the block on the left side.
Outputfor Each test scenario, output one line containing the maximum number of signals which is routed on the silicon Surface without crossing each other.
Sample Input46426315 1023456789101 887654321 9589231746 sample Output3914 Test Instructions: Remove some segments from the left side of the graph so that the remaining segments do not intersect, ask the maximum number of lines left to be solved: by observing that the remaining segments do not intersect, it is required that the right side of the line is a monotonically increasing sort because the data is large to avoid timeouts The principle of finding the maximum length of the maximal increment sequence by the dichotomy method: Use a set of data to illustrate: 5 8 9 2 3 1 7 4 6 Obviously we can see that the longest subsequence is 2 3 4 6 length Four, set an array a [] to store the sub-sequence set Top=1 to the length of the subsequence; next we have a traversal first is 5 a[top++]=5, then 8 because 8>5 so a[top++]=8;9>8 so a[top++]=9 at this time the element in a array is 5 8 9; then traverse to 2, because 5 is the smallest and 2<5 in the current a array, so overwrite 5 with the second, then the array a becomes 2 8 9 and then iterates to 3 because 2<3<8 3 covers 8 and then the array a becomes 2 3 9 and then the same 1 overrides the 2;7 overlay 9;4 cover 7 ; until 6 o'clock because all the numbers in array A are smaller than 6, so a[top++]=6, the element in array A is 1 3 4 6 is the length of top, (this method can only be used to find the length of the maximum increment subsequence cannot print out the maximum increment subsequence) AC code:
#include <stdio.h> #include <string.h>int main () {int t;int p,top,l,r,mid,i,m;int a[44000];scanf ("%d", &t), while (t--) {scanf ("%d", &p), scanf ("%d", &a[0]), int top=0;for (i=1;i<p;i++) {scanf ("%d", &m); if (a[top]<m) a[++top]=m;else{l=0;r=top;mid=0; while (r>=l) { mid= (r+l)/2; if (A[mid] < m) L=mid+1; else r=mid-1; }
HDOJ 1950 bridging signals "two-point maximum ascending sub-sequence length"