点击打开链接

B - Bridging signals

'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

错误代码(一组数据行,怎么实现多组数据输入?)

Select Code

#include <stdio.h>
#include <cstring>
#include <algorithm>
#define INF 0x3f3f3f
using namespace std;
int dp[30020],a[30020];
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int m;
scanf("%d",&m);
for(int i=0; i<m ; i++)
{
scanf("%d",&a[i]);
dp[i]=INF;
}
for(int i=0; i<m; i++)
*lower_bound(dp,dp+n,a[i])=a[i]; //优化
printf("%d\n",lower_bound(dp,dp+m,INF)-dp);
}
return 0;
}

正确代码

Select Code

#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std; int a[41000];
int main()
{
int N,n,i,j,t;
scanf("%d",&N);
while(N--)
{
scanf("%d",&n);
scanf("%d",&t);
a[0]=t;
int top=1;
for(i=1; i<n; i++)
{
scanf("%d",&t);
if(t>=a[top-1])
a[top++]=t;
else
{
int z=0,q=top-1;
while(z<=q)
{
int mid=(z+q)/2;
if(a[mid]<t)
z=mid+1;
else
q=mid-1;
}
a[z]=t;
}
}
printf("%d\n",top);
}
return 0;
}

B - Bridging signals (LIS)的更多相关文章

  1. POJ 1631 Bridging signals(LIS O(nlogn)算法)

    Bridging signals Description 'Oh no, they've done it again', cries the chief designer at the Waferla ...

  2. POJ 1631 Bridging signals(LIS 二分法 高速方法)

    Language: Default Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1076 ...

  3. POJ 1631 Bridging signals(LIS的等价表述)

    把左边固定,看右边,要求线不相交,编号满足单调性,其实是LIS的等价表述. (如果编号是乱的也可以把它有序化就像Uva 10635 Prince and Princess那样 O(nlogn) #in ...

  4. HDU 1950 Bridging signals (LIS,O(nlogn))

    题意: 给一个数字序列,要求找到LIS,输出其长度. 思路: 扫一遍+二分,复杂度O(nlogn),空间复杂度O(n). 具体方法:增加一个数组,用d[i]表示长度为 i 的递增子序列的最后一个元素, ...

  5. ZOJ 1093 Monkey and Banana (LIS)解题报告

    ZOJ  1093   Monkey and Banana  (LIS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  6. 浅谈最长上升子序列(LIS)

    一.瞎扯的内容 给一个长度为n的序列,求它的最长上升子序列(LIS) 简单的dp n=read(); ;i<=n;i++) a[i]=read(); ;i<=n;i++) ;j<i; ...

  7. 最长递增子序列(LIS)(转)

    最长递增子序列(LIS)   本博文转自作者:Yx.Ac   文章来源:勇幸|Thinking (http://www.ahathinking.com)   --- 最长递增子序列又叫做最长上升子序列 ...

  8. Poj 2533 Longest Ordered Subsequence(LIS)

    一.Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...

  9. Poj 3903 Stock Exchange(LIS)

    一.Description The world financial crisis is quite a subject. Some people are more relaxed while othe ...

随机推荐

  1. python greenlet 背景介绍与实现机制

    最近开始研究Python的并行开发技术,包括多线程,多进程,协程等.逐步整理了网上的一些资料,今天整理一下greenlet相关的资料. 并发处理的技术背景 并行化处理目前很受重视, 因为在很多时候,并 ...

  2. 使用API调用外部程序并监控程序状态

    Public Type SHELLEXECUTEINFO    cbSize As Long    fMask As Long    hwnd As Long    lpVerb As String  ...

  3. 实现JNI的另一种方法:使用RegisterNatives方法传递和使用Java自定义类 (转)

    原帖地址:http://blog.csdn.net/qiuxiaolong007/article/details/7860610 除了使用传统方法实现JNI外,也可以使用RegisterNatives ...

  4. 关于setConnectTimeout和setReadTimeout的问题

    1.问题描述 这几天测试重构后的下载框架,发现在下载过程中如果网络中断或网络较差,个别应用的下载就会阻塞卡住,一直卡在 “正在下载 xx%”.   2.问题排查和定位 思考:网络差不应该报网络异常的错 ...

  5. selenium IDE测试中的坑

    selenium IDE工具是firefox自带的一个网页自动化测试工具,因为它是IDE所以它很方便使用,但也因为它是IDE所以它有那么些坑. 问题:selenium回放中timeout问题 网页的打 ...

  6. c++静态变量与菲静态变量

    刚开始用C++写程序,遇到了一个很奇怪的问题,就是在类定义的面定义了一个静态成员变量,但在使用时编译器报错称变量不是类的成员. 文件a.h内容: /**********************A.h* ...

  7. php多进程pcntl学习(采集新浪微博)

    上面2篇文都简明了多进程中一些需要注意的地方,这次用多进程配合curl_mulit_*来做新浪微博的采集. 先把知识点和值得注意的坑列出 /* 需求:开3个进程,并且模拟多线程来采集新浪微博用户信息, ...

  8. Python 中的POST/GET包构建以及随机字符串的生成-乾颐堂

    现在,我们来用Python,创建GET包和POST包. 至于有什么用处,大家慢慢体会. Python 中包含了大量的库,作为一门新兴的语言,Python 对HTTP有足够强大的支持. 现在,我们引入新 ...

  9. 解决 Windows 系统使用 Homestead 运行 Laravel 本地项目响应缓慢问题

    laravel-china.com: https://laravel-china.org/articles/9009/solve-the-slow-response-problem-of-window ...

  10. [Java] 通过XPath获取XML中某个节点的属性

    /** * Get PA Url * @author jzhang6 * @return url */ public String getPAUrl(){ String PAUrl = "& ...