Constructing Roads In JGShining's Kingdom(LIS)
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)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP)
HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP) 点我挑战题目 题目分析 题目大意就是给出两两配对的poor city和ric ...
- 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 ...
- Constructing Roads In JGShining's Kingdom(HDU1025)(LCS序列的变行)
Constructing Roads In JGShining's Kingdom HDU1025 题目主要理解要用LCS进行求解! 并且一般的求法会超时!!要用二分!!! 最后蛋疼的是输出格式的注 ...
随机推荐
- 13、scala模式匹配
1.模式匹配的基础语法 2.对类型进行模式匹配 3.对Array和List的元素进行模式匹配 4.case class与模式匹配 5.Option与模式匹配 1.模式匹配的基础语法 Scala提供了m ...
- CentOS6.9下NFS配置说明(转载)
NFS是Network File System的缩写,即网络文件系统.它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录.NFS客户端可以通过挂载(mount)的方式将NFS ...
- react typescript 子组件调用父组件
//父组件 import * as React from 'react'import { Input } from 'antd'const Search = Input.Searchimport &q ...
- 2 Button
// <summary> /// 设置透明按钮样式 /// </summary> private void SetBtnStyle(Button btn) { btn.Flat ...
- ES6学习历程(字符串的扩展)
字符串的扩展 在看这一节的时候前半部分写的都是关于unicode的内容,我个人感觉这部分在实际的开发中用的很少,所以不打算在做记录,等届时用到再有针对性的看,所以就将在ES6里面关于字符串操作的一些新 ...
- Dinic当前弧优化 模板及教程
在阅读本文前,建议先自学最大流的Ek算法. 引入 Ek的核心是执行bfs,一旦找到增广路就停下来进行增广.换言之,执行一遍BFS执行一遍DFS,这使得效率大大降低.于是我们可以考虑优化. 核心思路 在 ...
- PAT 1118 Birds in Forest
Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in ...
- 《hello-world》第八次团队作业:Alpha冲刺-Scrum Meeting 4
项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺 团队名称 <hello--worl ...
- 【codeforces 767B】The Queue
[题目链接]:http://codeforces.com/contest/767/problem/B [题意] 排队去办护照; 给你n个人何时来的信息; 然后问你应该何时去才能在队伍中等待的时间最短; ...
- JavaSE 学习笔记之StringBuffer(十五)
--< java.lang >-- StringBuffer字符串缓冲区: 构造一个其中不带字符的字符串缓冲区,初始容量为 16 个字符. 特点: 1:可以对字符串内容进行修改. 2:是一 ...