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. 用nginx实现分布式限流

    1.前言 一般对外暴露的系统,在促销或者黑客攻击时会涌来大量的请求,为了保护系统不被瞬间到来的高并发流量给打垮, 就需要限流 . 本文主要阐述如何用nginx 来实现限流. 听说 Hystrix 也可 ...

  2. SPPNet论文翻译-空间金字塔池化Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition

    http://www.dengfanxin.cn/?p=403 原文地址 我对物体检测的一篇重要著作SPPNet的论文的主要部分进行了翻译工作.SPPNet的初衷非常明晰,就是希望网络对输入的尺寸更加 ...

  3. Html test

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  4. Hibernate连接池断开自动重连

    异常: javax.servlet.ServletException: org.springframework.transaction.CannotCreateTransactionException ...

  5. Java Web学习总结(23)——Distributed Configuration Management Platform(分布式配置管理平台)

    专注于各种 分布式系统配置管理 的通用组件/通用平台, 提供统一的配置管理服务. 主要目标: 部署极其简单:同一个上线包,无须改动配置,即可在 多个环境中(RD/QA/PRODUCTION) 上线 部 ...

  6. 2017沈阳网络赛hdu6199 gems gems gems

    gems gems gems Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) P ...

  7. FOJ2250 不可能弹幕结界

    Problem 2250 不可能弹幕结界 Time Limit: 1000 mSec    Memory Limit : 65536 KB Problem Description 咲夜需要穿过一片弹幕 ...

  8. noip模拟赛 拼不出的数

    分析:如果每个数可以选任意多次,那么就是一个很普通的dp问题,这里每个数只能选一次,还是考虑dp,设f(i)表示1~i是否都能选上.考虑下一个数j,如果j > i + 1,那么i+1这个数就选不 ...

  9. Sencha Touch 2.1学习图表Chart概述

    Extjs.chart提供了可视化展现数据的能力,每个图表可以绑定到数据模型Ext.data.Store上, 并随着数据的变换可以自动的更新图表 一个图表对象包括图标风格.坐标(axes).序列(se ...

  10. POJ 3061 Subsequence 尺取

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14698   Accepted: 6205 Desc ...