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. JavaFX桌面应用开发-鼠标事件和键盘事件

    鼠标相关事件的操作初始代码 package application; import javafx.application.Application;import javafx.event.ActionE ...

  2. profiler-gpu分析记录

    查看 Android 手机芯片信息下面以 夜神模拟器为例 D:\cmderλ adb devices # 1. 列出安卓设备List of devices attached127.0.0.1:6200 ...

  3. BZOJ 2894: 世界线 广义后缀自动机

    Code: #include<bits/stdc++.h> #define maxn 300000 #define ll long long using namespace std; ve ...

  4. https webservice通讯 参考网址 http://blog.csdn.net/small____fish/article/details/8214938

    一.生成密钥库和证书可参考以下密钥生成脚本,根据实际情况做必要的修改,其中需要注意的是:服务端的密钥库参数“CN”必须与服务端的IP地址相同,否则会报错,客户端的任意. 1.生成服务器证书库keyto ...

  5. oracle的递归运算(树运算) 无限树形

    oracle的递归运算(树运算)start with org_id ='1'connect by prior parent_id=son_id 1.前言   oracle的递归运算,在我们web页面的 ...

  6. python爬虫20 | 小帅b教你如何使用python识别图片验证码

    当你在爬取某些网站的时候 对于你的一些频繁请求 对方会阻碍你 常见的方式就是使用验证码 验证码的主要功能 就是区分你是人还是鬼(机器人) 人 想法设法的搞一些手段来对付技术 而 技术又能对付人们的想法 ...

  7. SFTP文件上传下载

    http://www.cnblogs.com/longyg/archive/2012/06/25/2556576.html  (转载)

  8. 【Codeforces 27A】Next Test

    [链接] 我是链接,点我呀:) [题意] 让你求没出现过的最小值 [题解] 模拟..for一下就好 [代码] import java.io.*; import java.util.*; public ...

  9. C/C++ uchar的一个有趣用法

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51377490 图像处理中常常使用的一种 ...

  10. 洛谷 P1851 好朋友

    题目背景 小可可和所有其他同学的手腕上都戴有一个射频识别序列号码牌,这样老师就可以方便的计算出他们的人数.很多同学都有一个“好朋友” .如果 A 的序列号的约数之和恰好等于B 的序列号,那么 A的好朋 ...