http://acm.hdu.edu.cn/showproblem.php?pid=1025

题意:富人路与穷人路都分别有从1到n的n个点,现在要在富人点与穷人点之间修路,但是要求路不能交叉,问最多能修多少条。

思路:穷人路是按顺序给的,故求富人路的最长上升子序列即可。由于数据范围太大,应该用O(nlogn)的算法求LIS。

 #include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int N=;
int r[N],d[N];
int main()
{
int n,cnt = ,x,y,k;
while(~scanf("%d",&n))
{
cnt++;
memset(d,,sizeof(d));
for (int i = ; i < n; i++)
{
scanf("%d %d",&x,&y);
r[x] = y;
}
k = ;
d[k] = r[];
for (int i = ; i <= n; i++)
{
int low = ;
int high = k;
int mid;
while(low <= high)
{
mid = (low+high)/;
if (d[mid] < r[i])
low = mid+;
else
high = mid-;
}
d[low] = r[i];
if (low > k)
k = low;
}
if (k==)
printf("Case %d:\nMy king, at most %d road can be built.\n\n",cnt,k);
else
printf("Case %d:\nMy king, at most %d roads can be built.\n\n",cnt,k);
}
return ;
}

Constructing Roads In JGShining's Kingdom(LIS)的更多相关文章

  1. HDU1025:Constructing Roads In JGShining's Kingdom(LIS)

    Problem Description JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which ...

  2. HDU 1025 Constructing Roads In JGShining's Kingdom(二维LIS)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  3. hdu--(1025)Constructing Roads In JGShining's Kingdom(dp/LIS+二分)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  4. HDU 1025:Constructing Roads In JGShining's Kingdom(LIS+二分优化)

    http://acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Problem Des ...

  5. Constructing Roads In JGShining's Kingdom(HDU 1025 LIS nlogn方法)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  6. hdu 1025:Constructing Roads In JGShining's Kingdom(DP + 二分优化)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  7. HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP)

    HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP) 点我挑战题目 题目分析 题目大意就是给出两两配对的poor city和ric ...

  8. HDU 1025 Constructing Roads In JGShining's Kingdom[动态规划/nlogn求最长非递减子序列]

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  9. Constructing Roads In JGShining's Kingdom(HDU1025)(LCS序列的变行)

    Constructing Roads In JGShining's Kingdom  HDU1025 题目主要理解要用LCS进行求解! 并且一般的求法会超时!!要用二分!!! 最后蛋疼的是输出格式的注 ...

随机推荐

  1. log4j最全教程

    (转自http://www.codeceo.com/article/log4j-usage.html) 日志是应用软件中不可缺少的部分,Apache的开源项目log4j是一个功能强大的日志组件,提供方 ...

  2. BeginEditorCommand()

    BeginEditorCommand();开始把焦点给CAD CompleteEditorCommand();焦点给窗体

  3. anguar相关

    1.创建组件 在某目录下创建组件  ng g c content/membersManage 2.创建服务 在某目录下创建服务  ng g service services/storage 2.创建模 ...

  4. @Override注解

    @Override注解对于代码可读性的提升十分巨大 而且良好的可读性是一个优秀程序员必备的基础素养

  5. How To: set udev rule for setting the disk permission on ASM disks when using multipath on Linux 6.x

    在RHEL6.4上安装11gR2的RAC时,使用了MULTIPATH来聚合绑定多路径的磁盘,并且修改磁盘的权限,赋予grid:asmadmin用户和组. 此时,在安装时可以发现磁盘,日志如下 INFO ...

  6. [HDU5807] Keep In Touch

    \(Keep\ In\ Touch\):保持联络 \(Informatik\ verbindet\ dich\ und\ mich.\) 信息将你我连结? 发现这个方程很容易列出来. \(f[i][j ...

  7. 65.dynamic mapping

    主要知识点: 理解dynamic mapping 定制dynamic mapping 更改default dynamic mapping     一.理解dynamic mapping 1.基本概念 ...

  8. 第三节:Web爬虫之BeautifulSoup解析库

    Beautiful Soup官方说明: Beautiful Soup提供一些简单的.python式的函数用来处理导航.搜索.修改分析树等功能.它是一个工具箱,通过解析文档为用户提供需要抓取的数据,因为 ...

  9. 《hello-world》第八次团队作业:Alpha冲刺-Scrum Meeting 5

    项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺 团队名称 <hello--worl ...

  10. Sum of Medians

    Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes In one well-known a ...