题意:贫穷和富有的城市都按顺序1-n排列,需要在中间建造尽可能多的道路,最多可以建造多少条?

解:如果条件这样给出,贫穷的城市按顺序排列,并且按顺序给出每个贫穷城市需要的资源,那么能建造的最多的道路数就是这个顺序中的最长上升子序列的长度。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map> using namespace std;
typedef long long ll; const int maxn=1e5+; ll n,a[maxn];
ll dp[maxn]; ll lower_bound(ll *a,int x,int y,ll v){
int m;
while(x<y){
m=x+(y-x)/;
if(a[m]>=v)y=m;
else x=m+;
}
return x;
} ll q[maxn],r[maxn]; int main(){
int o=;
while(scanf("%lld",&n)!=EOF){
for(int i=;i<n;i++){
scanf("%lld%lld",&q[i],&r[i]);
}
for(int i=;i<n;i++){
a[q[i]-]=r[i]-;
}
int m=;
for(int i=;i<n;i++){
if(m==||dp[m-]<a[i]){
dp[m++]=a[i];
}else{
ll j=lower_bound(dp,,m,a[i]);
dp[j]=a[i];
}
/*验证正确性
for(int j=0;j<m;j++){
printf("%lld ",dp[j]);
}printf("\n");
*/
}
printf("Case %d:\n",o++);
printf("My king, at most %d road",m);
if(m>)printf("s");
printf(" can be built.\n\n"); }
return ;
}

hdu 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列)的更多相关文章

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

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

  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. [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)

    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(DP + 二分优化)

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

  5. 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 ...

  6. HDU 1025 Constructing Roads In JGShining's Kingdom(求最长上升子序列nlogn算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 解题报告:先把输入按照r从小到大的顺序排个序,然后就转化成了求p的最长上升子序列问题了,当然按p ...

  7. HDU 1025 Constructing Roads In JGShining's Kingdom(DP+二分)

    点我看题目 题意 :两条平行线上分别有两种城市的生存,一条线上是贫穷城市,他们每一座城市都刚好只缺乏一种物资,而另一条线上是富有城市,他们每一座城市刚好只富有一种物资,所以要从富有城市出口到贫穷城市, ...

  8. hdu 1025 Constructing Roads In JGShining’s Kingdom 【dp+二分法】

    主题链接:pid=1025">http://acm.acmcoder.com/showproblem.php?pid=1025 题意:本求最长公共子序列.但数据太多. 转化为求最长不下 ...

  9. hdu 1025 Constructing Roads In JGShining's Kingdom

    本题明白题意以后,就可以看出是让求最长上升子序列,但是不知道最长上升子序列的算法,用了很多YY的方法去做,最后还是超时, 因为普通算法时间复杂度为O(n*2),去搜了题解,学习了一下,感觉不错,拿出来 ...

  10. 最长上升子序列 HDU 1025 Constructing Roads In JGShining's Kingdom

    最长上升子序列o(nlongn)写法 dp[]=a[]; ; ;i<=n;i++){ if(a[i]>dp[len]) dp[++len]=a[i]; ,dp++len,a[i])=a[i ...

随机推荐

  1. 你还用拼音为变量命名?新人OIer别傻了,教你写出优质代码

    本篇文章适用语言:python,c++,Java.(其实我就是随便bb) 我们在编辑代码的时候,不免拿其他人的代码进行学习,或者将自己的代码拿给别人修改.这个时候,如何让别人快速读懂你的代码,是提升效 ...

  2. crul 命令访问公网 dns解析错误 程序报错

    今天机房几台服务器都无法访问公网接口,原因是——解析公网域名出错,具体情况如下 ping  公网ip或者域名  都没有问题 curl 公网域名 出错 curl -4  访问公网域名没有问题 综合分析 ...

  3. MySQL常用语法总结

    一,学习mysql的前戏 1:基础入门命令 show databases: #查看当前MySQL中的所有数据库 create 数据库名: #创建新的数据库 use 数据库名: #使用该数据库 show ...

  4. MacBook Pro突然蓝牙突然消失

    刚才想用蓝牙,发现蓝牙居然不可用,硬件信息也无法找到,分享一个方法:

  5. 制作OpenOffice的Docker镜像并添加中文字体解决乱码问题

    官网下载openoffice http://www.openoffice.org/download/index.html 本文使用的是Docker官方发布的CentOS7镜像作为基础镜像.镜像的获取方 ...

  6. tensorflow开发环境版本组合

    记录下各模块的版本 tensorflow 1.15.0       print tf.__version__ cuda 10.0.130            nvcc -v cudnn 7.6.4  ...

  7. c语言标准I/O

    头文件 <stdio.h> 打开/关闭文件 FILE *fopen(char *filename, char *mode); 如果正常打开返回FILE指针,否则返回NULL mode常用值 ...

  8. axios,vue-echarts, async, vue 图表数据处理; axios 跨域代理; 异步同步请求接口;生命周期函数

    1.vue-echarts 安装和组件引用 插件官网 https://github.com/ecomfe/vue-echarts 安装 npm install eacharts vue-echarts ...

  9. Oracle行结果合计的实现

    Oracle行结果合计的实现,主要应用于日期结果的集计,下面是具体的实现代码. With AA as ( select 'A' tNo ,  10 B from dual union select ' ...

  10. 【STM32H7教程】第47章 STM32H7的FMC总线基础知识和HAL库API

    完整教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=86980 第47章       STM32H7的FMC总线基础知识和HA ...