首页 > 其他分享 >HDU 1950

HDU 1950

时间:2023-08-15 17:33:10浏览次数:36  
标签:HDU int two signals 1950 each ports left


Bridging signals

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

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


#include <stdio.h>
#include <string.h>

int a[40010];
int b[40010];

int Sear(int num,int right)
{
    int left=1;
    while(left<=right)
    {
        int middle=(left+right)/2;
        if(num>=b[middle])
            left=middle+1;
        else
            right=middle-1;
    }
    return left;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        memset(b,0,sizeof(b));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        b[1]=a[1];
        int k=1;
        for(int i=2;i<=n;i++)
        {
            if(a[i]>b[k])
                b[++k]=a[i];
            else
            {
                int pos=Sear(a[i],k);
                b[pos]=a[i];
            }
        }
        printf("%d\n",k);
    }
    return 0;
}




标签:HDU,int,two,signals,1950,each,ports,left
From: https://blog.51cto.com/u_3936220/7091420

相关文章

  • HDU 1087 (LIS)
    SuperJumping!Jumping!Jumping!TimeLimit:2000/1000MS(Java/Others)  MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):28091  AcceptedSubmission(s):12529ProblemDescriptionNowadays,akindofchessgamecalled“SuperJumping!Jump......
  • HDU 3478
    CatchTimeLimit:2000/1000MS(Java/Others)  MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):1389  AcceptedSubmission(s):682ProblemDescriptionAthiefisrunningaway!Wecanconsiderthecitywherehelocatesasanundirectedgrap......
  • HDU 5364
    DistributionmoneyTimeLimit:2000/1000MS(Java/Others)  MemoryLimit:65536/65536K(Java/Others)TotalSubmission(s):310  AcceptedSubmission(s):186ProblemDescriptionAFAwanttodistributionhermoneytosomebody.Shedividehermoneyintons......
  • HDU 5366
    ThemookjongTimeLimit:2000/1000MS(Java/Others)  MemoryLimit:65536/65536K(Java/Others)TotalSubmission(s):326  AcceptedSubmission(s):252ProblemDescription![](../../data/images/C613-1001-1.jpg)ZJiaQwanttobecomeastrongman,sohed......
  • HDU 2444
    TheAccomodationofStudentsTimeLimit:5000/1000MS(Java/Others)  MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):3561  AcceptedSubmission(s):1656ProblemDescriptionThereareagroupofstudents.Someofthemmayknoweachother,......
  • HDU 1698(线段树 区间更新)
    JustaHookTimeLimit:4000/2000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):23481    AcceptedSubmission(s):11758ProblemDescriptionInthegameofDotA,Pudge’smeathookisactuallythemosthorr......
  • HDU 3829 Cat VS Dog 猫和狗(二分图)结题报告
    听学长说这道题很ex,但是思路想到的话还是挺简单的。可能是受上一道题(放置机器人)的启发,也是找互相冲突的点连线。但是并不是完全一样(废话)放置机器人那道题是找到冲突点连线后直接求最大匹配即可。这道题稍微把思路变换一下,求出最大完美匹配数\(n\)后,说明有\(n*2\)个人的喜好......
  • HDU7326 string magic(Easy Version)
    HDU7326stringmagic(EasyVersion)tag:回文自动机题目链接题意:多组样例,每组输入一字符串(长度1e5以内),输出满足下列条件的子串个数:该串由两个完全相同的回文串拼接而成做法:字符串的题目一般都比较板,洛谷的P4287可以说是这道题目的原题,我们先看看原题是怎么做的P4287双......
  • hdu7365 0 vs 1
    0vs1首先如果两端不同肯定只能直接选。两端都选不了直接失败。不妨设现在是zero在选,从左边来010101交替,如果先出现了一个00比如01010100.....10那么我们就能从这边选,因为one只能跟着我们选这边,最后会出现两边都是0的情况。从右边来同理。假如是0101010交替,那么肯定是平......
  • HDU 多校 Round #6 题解
    HDU多校Round#6题解\(\text{ByDaiRuiChen007}\)A.CountProblemLink题目大意求有多少个长度为\(n\),字符集大小为\(m\)的字符串有长度为\(n-k\)的周期。数据范围:\(n,m,k\le10^{18}\)。思路分析\(k=n\)时答案为\(m^n\),否则转为有长度为\(k\)的Border,答案......