HDU-1025

杭电ACM OJ 1025 Constructing Roads In JGShining's Kingdom 最长上升子序列 O(nlogn)算法详解+回溯暴力解决+动态规划dp优雅解决 Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 26933    Accepted Submission(s): 7655 Proble 阅读详情

JGShining’s kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines.

Half of these cities are rich in resource (we call them rich cities) while the others are short of resource (we call them poor cities). Each poor city is short of exactly one kind of resource and also each rich city is rich in exactly one kind of resource. You may assume no two poor cities are short of one same kind of resource and no two rich cities are rich in one same kind of resource.

With the development of industry, poor cities wanna import resource from rich ones. The roads existed are so small that they’re unable to ensure the heavy trucks, so new roads should be built. The poor cities strongly BS each other, so are the rich ones. Poor cities don’t wanna build a road with other poor ones, and rich ones also can’t abide sharing an end of road with other rich ones. Because of economic benefit, any rich city will be willing to export resource to any poor one.

Rich citis marked from 1 to n are located in Line I and poor ones marked from 1 to n are located in Line II.

The location of Rich City 1 is on the left of all other cities, Rich City 2 is on the left of all other cities excluding Rich City 1, Rich City 3 is on the right of Rich City 1 and Rich City 2 but on the left of all other cities … And so as the poor ones.

But as you know, two crossed roads may cause a lot of traffic accident so JGShining has established a law to forbid constructing crossed roads.

For example, the roads in Figure I are forbidden.
这里写图片描述

In order to build as many roads as possible, the young and handsome king of the kingdom - JGShining needs your help, please help him. ^_^
Input
Each test case will begin with a line containing an integer n(1 ≤ n ≤ 500,000). Then n lines follow. Each line contains two integers p and r which represents that Poor City p needs to import resources from Rich City r. Process to the end of file.
Output
For each test case, output the result in the form of sample.
You should tell JGShining what’s the maximal number of road(s) can be built.

Sample Input

2
1 2
2 1
3
1 2
2 3
3 1

Sample Output

Case 1:
My king, at most 1 road can be built.

Case 2:
My king, at most 2 roads can be built.

Hint
Huge input, scanf is recommended.

最长上升子序列不需要打印序列(nlogn)
//闲话:这题很坑!!!注意单复数,还有空行QAQ

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 500050
#define INF 0x3f3f3f3f
int dp[maxn], f[maxn];
int main()
{
    int i , j, k, n, x, y, ans, times = 0, left, right, mid, temp;
    while(~scanf("%d", &n)){
        for(i = 1; i <= n; ++i){
            scanf("%d %d", &x, &y);
            f[x] = y;
        }
        printf("Case %d:\n", ++times);
        memset(dp, 0, sizeof(dp));
        ans = 1;
        dp[1] = f[1];
        for(i = 2; i <= n; ++i){
            if(dp[ans] <= f[i]){
                dp[++ans] = f[i];
            }
            else{
                left = 1; right = ans;
                //二分查找
                while(right >= left){
                    mid = (left + right)/2;
                    if(dp[mid] > f[i])
                        right = mid - 1;
                    else
                        left = mid + 1;
                }
                dp[left] = f[i];
            }
        }
        if(ans != 1)
            printf("My king, at most %d roads can be built.\n\n",ans);
        else
            printf("My king, at most 1 road can be built.\n\n");
    }
}
基于卡尔曼滤波的视频目标跟踪实战:运动小球轨迹平滑 视频目标跟踪中,单帧检测结果往往包含噪声,甚至出现目标短暂丢失。卡尔曼滤波是一种基于状态空间模型的递归估计算法,通过预测与更新两个步骤,将运动模型预测与观测数据融合,实现对目标状态的平滑估计。其技术价值在于计算量低、实时性强,能有效处理检测噪声和丢帧问题。在机器人视觉、工业检测等场景中,常被用于对运动目标进行连续稳定的轨迹跟踪。本文以运动小球跟踪为切入点,结合完整代码与数据集,详细讲解卡尔曼滤波的五个核心公式、Python实现、Q/R参数调优以及目标丢失时的处理策略,帮助初学者快速上手并落地到实际项目中。 阅读详情

相关推荐

杭电ACM1002-1025VC版个人解答

该文件包含了杭电ACM第1002至1025题得个人解题答案,有些答案包含了两种至三种解答。

杭电ACM OJ 1025 Constructing Roads In JGShining‘s Kingdom 最长上升子序列 O(nlogn)算法详解+回溯暴力解决+动态规划dp优雅解决

Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 26933Accepted Submission(s): 7655 Problem Description JGShining's kingdom consists of 2n(n is no ...

u011250186的博客 402

宝塔面板一键部署Z-Blog博客 - 内网穿透实现公网访问

Ubuntu系统作为Linux系统的一个重要分支,既有Linux系统的轻量化、高扩展性和长时间稳定运行,也拥有Windows一样的友好图形界面,因此可以作为熟悉服务器系统的良好选择。对于笔者来说,ubuntu系统最大的用处,就是可以让家里老旧的电脑重焕生机,让本已退居二线的电脑与cpolar内网穿透软件搭配,成为私人服务器,搭建自己喜欢的各种网站。今天,笔者就为大家介绍,如何使用cpolar内网穿透+Z-blog搭建私人博客网站。

m0_74808907的博客 3152

最长单调子序列例题

1. HDU 1025 Constructing Roads In JGShining's Kingdom Problem Description JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines. Half of...

zamaochick的博客 493

告别配置烦恼!保姆级教程:在Windows 10/11上为QT5.14.2配置MSVC2017编译器(附VS2022组件避坑指南)

本文提供了一份详细的保姆级教程,指导如何在Windows 10/11上为QT5.14.2配置MSVC2017编译器,包括VS2022组件避坑指南。从环境准备到关键配置,再到调试工具验证和Qt Creator中的编译器设置,一步步解决常见问题,帮助开发者快速搭建稳定可靠的开发环境。

weixin_30615767的博客 504

Apache Doris IP变更问题详解

Apache Doris IP变更问题详解

ith321的博客 7278

【HDU 杭电OJ 1025 Constructing Roads In JGShining's Kingdom】

Constructing Roads In JGShining’s KingdomDescription JGShining’s kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines. Half of these cities are rich i

楚江枫 523

GlobalPlatform Technology Secure Channel Protocol ‘03‘ 标准 - 安全通道协议简介

按照GlobalPlatform Technology Secure Channel Protocol '03' (SCP03)标准,描述了如何利用S-MAC,S-RMAC,S-ENC进行安全通信的过程。

mmmx777的专栏 6101

杭电OJ——1025 Constructing Roads In JGShining's Kingdom(比较有趣的一道题目,思路详解)...

Constructing Roads In JGShining's Kingdom Problem Description JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines. Half of these...

编程语言小筑 321

VN1640 CH5 I/O通道终极指南:【从硬件原理—>工程实战—>自动化测试实战】

摘要:本文详细解析Vector VN1640 CH5 I/O通道的硬件原理与工程应用,涵盖模拟输入(AIN)、数字输入(DIN)和数字输出(DOUT)三大功能模块的配置指南。通过硬件隔离设计实现高精度信号采集与驱动控制,重点分析开漏输出特性及保护机制。提供PWM控制、ECU上电时序测试、传感器闭环控制等实战案例的CAPL脚本代码,并强调多设备同步采集的精准性(时间偏差<1µs)。适用于汽车电子HIL测试、ECU信号监测等场景,所有方案均通过实际项目验证。

汽车控制器系统开发、VIL测试、HIL测试、MIL测试、EMS电喷系统标定与开发、热管理系统标定 765

.net core 下的PostgreSQL 异常排查—— Exception while reading from stream (0x80004005)

最近以PostgreSQL为存储介质,实现了分布式缓存的一个组件开发,在经过开发环境的测试后,顺利推送到产品组的手里,经过开发环境的验证后,终于发布到测试环境了,但问题来了,产品组反应频繁出现访问异常,返回的信息大致是:Exception while reading from stream … (0x80004005) ????欢迎点赞 :???? 收藏 ⭐留言 ???? 如有错误敬请指正,赐人玫瑰,手留余香! ????本文作者:由webmote 原创,首发于 【CSDN】 ????作者格言: 生活在

网尘的技术专栏 5849

HDU 1025 Constructing Roads In JGShining's Kingdom LIS -

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1025 要用nlogn的算法,不然会超时 参见博客讲解:http://blog.csdn.net/kaitangshouljz/article/details/41074187?locationNum=7 #include #include #include #include using

BRCOCOLI的博客 304

【代码审计】专栏文章汇总

代码审计基础 代码审计基础 源代码审计思路(上) 源代码审计思路(下) 常见漏洞审计 认证会话管理(上) 认证会话管理(下) 输入输出验证 授权管理审计 业务安全审计 第三方组件审计

武天旭的博客 4851

【dp+二分】HDU 1025

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 题目大意:现在有两条平行线,给出两条线上的点的若干个匹配关系,求最多有多少对使得匹配连线不相交 思路:非常明显,这个题可以转化成按照一个量排序,求另一个量的最长上升子序列,但是这个题的范围很大,N^2要TLE……所以得用n上升子序列logn的办法求最长  代码:#inclu

390

基于容积卡尔曼滤波的弹目相对姿态估计算法及其在导弹末端制导中的应用

本文针对导弹末端制导中的强非线性姿态估计问题,提出了一种基于容积卡尔曼滤波(CKF)的弹目相对姿态估计算法。通过建立包含视线角、角速率和相对距离的6维状态模型,利用三阶球面-相径容积准则精确逼近非线性状态分布,避免了传统EKF的线性化误差。在MATLAB/Simulink仿真中,CKF表现出比EKF更高的视线角速率估计精度和更快的收敛速度,最终显著减小了脱靶量,验证了其在提升导弹末端制导精度方面的有效性。该算法计算复杂度适中,适合工程实现,为高精度非线性姿态估计提供了新思路。

AI的内部世界的博客 108

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

HDU 1025 Constructing Roads In JGShining‘s Kingdom

Constructing Roads In JGShining’s Kingdom http://acm.hdu.edu.cn/showproblem.php?pid=1025 分析 最长上升子序列 O(nlogn) 代码 // hdu 1025 Constructing Roads In JGShining's Kingdom #include <bits/stdc++.h> using namespace std; #define MXN 500010 #define fmt "Case

jpphy0的博客 185

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

hdu 1025 Constructing Roads In JGShining's Kingdom dp(LIS)

hdu 1025 Constructing Roads In JGShining's Kingdom http://acm.hdu.edu.cn/showproblem.php?pid=1025   二分求最长上升子序列,长度即可建路数   //hdu 1025 #include #include #include #include #include #include usi

倩 798

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

hdu 1025 && hdu 1058

hdu 1025 #include #include #include using namespace std; int dp[500005], s[500005], len, Case=0; int search(int a, int b, int c) { int mid; while(ab) { mid = (a + b) / 2;

qq_35567127的博客 272

hdu 1025 Constructing Roads In JGShining's Kingdom

http://acm.hdu.edu.cn/showproblem.php?pid=1025 题意:题目的意思就是有两种城市,穷和富,要富的运到穷的里面问你最多能建几条路。 思路:就是按穷的递增序列来找富的城市里的最大上升子序列。就是LIS法,因为有500000个数据所以用普通的方法肯定超时,那么就用二分查找就可以了。每次就是找第一个比这个数大的数如果没有就放在最右边把最长的序列加一,否则把第...

weixin_30525825的博客 76

HDU - 1025 -最长上升子序列nlogn

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 刚开始题目理解错了,第一个数字是a数组下标,第二个是数组的值,nlogn算法写法用到了二分查找 还有这题输出很坑,一个道路是是road,两个以上是roads #include<iostream> #include<cstdio> #include<cstri...

qmi_q米的博客 619

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

题目地址:HDU 1025 用简单的DP复杂度为n*n 会TLE  找了一个用另外一种方法做的 复杂度为nlogn 最长上升子序列 #include #include #include #include #include #define N 500050 using namespace std; int road[N],n; int dp[N],m; int find(in

胡七一upup 255

HDU 1025 解题报告

这是一道 LIS (最长升序子序列)的问题。 这题是不需要考虑元素重复的情况。 数据比较大,需要用 O(nlogn)才能解题。 注意输出有 load和 loads 的坑。。。代码链接:HDU 1025

学无止境 1714

HDU1025(Constructing Roads In JGShining's Kingdom)

这道题我提交了好几次才过的,主要的因为TLE,因为我的算法效率是O(n^2),在网上找到了更高效的是O(n*logn).在这里我附上我两种代码. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 TLE代码: Code#include<iostream>#include<algorithm>usingnamesp...

weixin_30414305的博客 65

HDU1025最长上升子序列问题

HDU25 最长上升子序列问题 下面向上面边线,只要保证从左到右目的连接目的地是按序上升即可保证不交叉,此问题则转化成了最长上升子序列问题。 /* * hdu 1025 * 请求序列构成按序增加即可达到连线不相交,序列长度即题目解,因此题目转化为求最长上升子序列问题。 * 注意:仅有一条路时,为road,否则为roads。 */ #include <iostream> #in...

qq_24489251的博客 222

【HDU 1025】Constructing Roads In JGShining‘s Kingdom(二分法&最大上升子序列 详解)

Constructing Roads In JGShining's Kingdom HDU 1025 题意描述:多实例,给出想要修的道路数量,以及这条路连通的穷富城市的编号。不会有某一个城市想连通两个城市的情况,穷富城市编号都是从1开始依次编号,不允许出现交叉道路的情况,求可以修的最多道路数量。 解题思路:道路情况有很多,我们需要舍去会造成道路交叉的某道路,利用一个数组find[],它含有的元素的个数是当前上升子序列的个数(除0),也就是find数组中是递增的。当有数据不加入find数组中,要更新前面

m0_58245389的博客 183

hdu 1025 最长严格上升子序列

原题连接: http://acm.hdu.edu.cn/showproblem.php?pid=1025

ditop. 406
上一篇: POJ 1837
下一篇: #424
Code_Diary
博客等级 码龄10年 3粉丝 30原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址