POJ 1631 Bridging signals
来源:互联网 发布:1.1初识动画软件教案 编辑:程序博客网 时间:2024/06/06 00:41
Description
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
Output
Sample Input
4642631510234567891018876543219589231746
Sample Output
3914
Source
/*
http://acm.pku.edu.cn/JudgeOnline/problem?id=1631
DP+二分查找
一开始没有使用二分查找,时间复杂度是n ^ 2,结果超时
后来改用二分,时间复杂度是nlgn,AC
二分的思路是:
使用bsVal来保存当前长度的序列中最小的point位置
比如bsVal[2] = 3意味着,长度为二的序列中最小的位置是3
*/
#include <iostream>
#define maxv(a, b) ((a) >= (b) ? (a) : (b))
#define MAX_N 40000
using namespace std;
int maxData[MAX_N + 1];
int input[MAX_N + 1];
int maxP;
int bsVal[MAX_N + 1];
void binarySearch(int curPos)
{
int l = 1, r = maxP, mid;
while(l <= r)
{
mid = (l + r) / 2;
if(bsVal[mid] < input[curPos])
l = mid + 1;
else
r = mid - 1;
}
maxData[curPos] = l;
bsVal[l] = input[curPos];
maxP = maxv(maxP, l);
}
int main()
{
int caseNum, pNum, i, j;
scanf("%d", &caseNum);
for(i = 1; i <= caseNum; i++)
{
maxP = 1;
scanf("%d", &pNum);
for(j = 1; j <= pNum; j++)
{
scanf("%d", &input[j]);
maxData[j] = 1;
if(j == 1)
{
bsVal[1] = input[j];
continue;
}
binarySearch(j);
}
printf("%d/n", maxP);
}
return 0;
}
- POJ 1631 Bridging signals
- Bridging signals POJ 1631
- poj 1631 Bridging signals
- poj 1631 Bridging signals
- poj 1631 Bridging signals
- POJ 1631 Bridging signals
- POJ-1631-Bridging signals
- poj 1631--Bridging signals
- POJ 1631 Bridging signals
- POJ 1631 Bridging signals
- poj 1631 Bridging signals
- poj 1631 Bridging signals
- POJ - 1631 Bridging signals
- poj-1631-Bridging signals
- poj 1631 Bridging signals
- POJ 1631 Bridging signals
- poj 1631 Bridging signals
- POJ 1631 Bridging signals(LIS)
- 英文版操作系统中,如何在控制台中输入中文
- 书架评论
- JAVA中窗体居中及关闭
- PDH二次群复接
- document.forms用法
- POJ 1631 Bridging signals
- Java static 一些说明
- sql 模糊查询
- 综合对比各个设计模式的思想
- 关于 解决 Ubuntu 9.04 desk wubi 安装 停在 95%的问题
- 一些 『企业信息门户解决方案』 链接
- 在 CentOS 5.x 下编译 RADVISION H.323 Protocol Toolkit 5.5
- pku 1050 To the Max
- 什么时候用索引组织表,什么时候用堆表