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

链式中介效应结果解读:从Bootstrap置信区间到实践意义 本文深入解析链式中介效应结果的解读方法,从Bootstrap置信区间的应用到实践意义的阐述。通过实际案例展示如何分析总效应、直接效应和间接效应,并强调效应量评估的重要性。文章还提供了构建逻辑解释的三步法,以及敏感性分析和报告撰写的实用技巧,帮助研究者准确解读链式中介效应。 阅读详情

Constructing Roads In JGShining’s Kingdom

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 23439 Accepted Submission(s): 6705

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

题意:
求最长上升子序列长度.

解题思路:
分出两个数组,A数组存原数组,B数组存最长上升子序列.
实现过程是从头遍历A数组,如果遍历到的这个数大于等于B数组的最后一个,那么就将该数添加到B数组的末尾,否则在B数组中找到第一个大于该数的数,并将其替换(查找过程用二分实现,因为B数组在操作过程中一直保持有序).

AC代码:

#include<stdio.h>
const int maxn = 500010;
int a[maxn];
int b[maxn];
int search(int num,int low,int high)
{
    while(low<=high)
    {
        int mid = (low+high)>>1;
        //if(num == b[mid]) return mid; /*如果是严格上升*/
        if(num >= b[mid])   low = mid+1;
        else                high = mid-1;
    }
    return low;
}
int dp(int n)
{
    b[1] = a[1];
    int len = 1;
    for(int i = 2;i <= n;i++)
    {
        if(a[i] >= b[len])
            b[++len] = a[i];
        else
            b[search(a[i],1,len)] = a[i];
    }
    return len;
}
int main()
{
    int flag = 1;
    int n;
    while(~scanf("%d",&n))
    {
        int index;
        int num;
        for(int i = 1;i <= n;i++)
        {
            scanf("%d%d",&index,&num);
            a[index] = num;
        }
        int res = dp(n);
        printf("Case %d:\n",flag++);
        if(res == 1)  printf("My king, at most 1 road can be built.\n\n");
        else            printf("My king, at most %d roads can be built.\n\n",res);
    }
    return 0;
}
CEH Practical 实战考试真题与答案 CEH Practical 是 EC-Council 推出的Certified Ethical Hacker(CEH)认证项目中的一项高级动手实践考试。它不同于传统的理论考试,侧重于在真实环境中检验考生的实操能力。 阅读详情

相关推荐

SAP BAPI调用避坑指南:处理MD61/MD62计划独立需求时,这些参数和返回值你必须检查

本文详细解析了SAP BAPI调用中处理MD61/MD62计划独立需求的关键参数和返回值检查要点,包括版本控制、日期类型和删除标记等核心参数设置,以及常见错误排查和高级调试技巧,帮助开发者高效管理需求计划数据。

weixin_30316097的博客 611

hdu 1025 Constructing Roads In JGShining's Kingdom【即求最长上升子序列】

DP(呃,两边不交叉修路的那道。。。) 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth

free斩 1282

应用软件——Altium Designer 19 Gerber/坐标文件

如何输出Gerber文件 步骤如下: 打开需要输出的PCB文件 2. 设置原点坐标 3. 打开Gerber Files 选项,File–>Fabrication Opuputs–>Gerber Files。 4. General参数设置。 用于指定输出Gerber文件中使用的单位(Units)和格式(Format)。单位可以是公制(Millimeters)和英制(Inches);格式栏中2:3,2:4,2:5代表文件中使用的不同数据精度,其中2:3表示数据含2位整数3位小数;相应的,另外两个分

染血黑兔的博客 7203

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

Constructing Roads In JGShining’s Kingdom HDU - 1025 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

HHH_go_的博客 744

Python逻辑回归——以车险定价为例(附代码)

保费定价也成为费率厘定,是保险公司运营的环节之一。其过程是根据保单(被保险人)的损失经验和其他相关信息建立模型,并且对未来的保险成本(赔款、代理人佣金、一般管理费用、理赔费用以及支持该业务所需的资本金成本)进行预测的过程。保险公司实际使用的费率还会受到市场供求关系和公司自身发展战略的影响。汽车保险也称机动车辆保险,失意机动车辆本身及其第三者责任等为保险标的的一种运输工具险,在非寿险井算领域中占有重要地位。

m0_62929945的博客 1984

学Simulink--机器人基础关节控制场景实例:基于Simulink的无刷直流电机(BLDC)关节六步换相位置控制仿真

本文详细介绍了基于Simulink的BLDC六步换相位置控制仿真方法,针对机器人关节的低成本控制需求。重点阐述了霍尔定位、六步换相和位置闭环三大核心原理,通过Simulink建模实现了从霍尔信号处理到位置环控制的全流程。仿真结果表明,该系统可实现0.3°的定位精度和80ms的响应时间,满足教育机器人等应用场景需求。文章还提供了核心代码模块和参数设置方法,并探讨了转矩脉动抑制、无传感器控制等进阶优化方向,为低成本机器人关节驱动提供了实用解决方案。

amy_mhd的博客 152

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

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

Nothing_but_Fight的博客 234

LVGL 蜂巢气泡菜单(Hex Menu)

h。

摸鱼专家 176

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

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1025 题意:有n个穷城市,n个富城市,每个穷城市都要从某个富城市运输一种物资(穷城市和富城市的物资供需一对一),需要建立道路,但任意两条路不能交叉;穷城市和富城市分     别位列平行线两侧(均按1 - n 分布);    给出城市个数n,下面n行输入两个数字 p 和 r 表示穷城市p要从富城市r运

0x3f3f3f3f 446

(四)C++自制植物大战僵尸游戏启动流程

鼠标左键单机VS2022上方工具栏中进行项目启动。第一次启动项目需要编译项目中所有代码文件,编译生成需要一定的时间。不同性能的电脑需要消耗的时间差别可能较大,通常在几分钟到几十分钟之间。编译成功后会自动启动运行游戏。qi编译成功后自动启动运行游戏如下图。

尔灵尔亿的博客 2466

ADS基础教程16 - 存档和导入(workspace、cell、view)

选择workspace_Archive目录作为保存workspace归档的目录,点击打开进行目录选择,点击Finish保存目录。,选择cell_Archive目录作为保存cell归档的目录,点击打开进行目录选择,点击Finish保存目录。,选择view_Archive目录作为保存view归档的目录,点击打开进行目录选择,点击Finish保存目录。(2)在弹框中,可以选择点击Select将参考的条目添加进来,然后点击Next…(2)在弹框中,可以选择点击Select将参考的条目添加进来,然后点击Next…

XZ_ZC的博客 3703

【HDU 1025】Constructing Roads In JGShining's Kingdom(最长上升子序列LIS)

DescriptionJGShining’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

Ice_Confuse 559

013 PID参数整定:Ziegler-Nichols法

几年前在调试一台伺服压机,客户要求位置精度±0.01mm,响应时间小于50ms。我按照教科书上的经验值设了P=1.5,I=0.02,D=0.01,结果电机一启动就开始尖叫,位置超调直接干到0.3mm,然后开始震荡,像极了喝醉的舞者。现场工程师看我的眼神,就像在看一个刚毕业的实习生。那次之后我明白了一个道理:PID参数不是靠猜的,也不是靠经验公式硬套的。你需要一个系统的方法,而Ziegler-Nichols法就是那个让你从“瞎调”走向“有章可循”的起点。

m0_50546716的博客 101

hdu 1025 Constructing Roads In JGShining's Kingdom(树状数组求最长上升子序列)

Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11666    Accepted Submission(s): 3325 Problem

WEYuLi的专栏 949

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

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

学习了最长上升子序列,刚开始学的n^2的方法,然后就超时了,肯定超的,最大值都是500000,平方之后都12位 了,所以又开始学nlogn算法,找到了学长党姐的博客orz,看到了rating是浮云。。。确实啊,这些不必太关 注,作为一个动力就可以啦。没必要看的太重,重要的事学习知识。 思路: 这道题目可以先对一行排序,然后对另一行求最长上升子序列。。。 n^2算法: 序列a[n],设一

勿忘初心 682

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

最长上升子序列 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

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

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

倩 797

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

Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6420Accepted Submission(s): 1881 Problem D...

weixin_30535913的博客 119

HDU 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列LIS+二分)

Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 30627    Accepted Submission(s): 8707   Problem Des...

YIU 251

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

A - Constructing Roads In JGShining's Kingdom Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description JGShining's kingdom consists of 2n(

※夏日星空※ 268

【最长上升子序列+STL+lower_bound】HDU-1025 Constructing Roads In JGShining's Kingdom

注解 1、最长上升子序列问题,开设两个数组a和d,a[p]=r,求a数组中的最长上升子序列的元素个数。 2、以1—3,2—8,3—5,4—9,5—2,6—4,7—6,8—7,9—1这9组数为例,用二分的方法依次找到每一个待处理数字的位置再对所选序列进行调整,调整的方法就是将所处理数字按序插入所选序列中,用它替换比它大的下一个数,若所选序列不存在比它大的数,则将它直接加在所选序列的最后,序列最终...

zhanggirlzhangboy的博客 376

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

要求不相交,求最长上升子序列 #include #include #include #include #include #include #include #include using namespace std; #include #include #include #include #include #include #define cler(arr, val)

Kewowlo 669

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

解题报告:就是求最长上升子序列,一开始用的普通办法求的!直接TEL;就在网上找了一个时间复杂度为O(nlogn)的算法,其算法思想为:(网上找的)假设要寻找最长上升子序列的序列是a[n],然后寻找到的递增子序列放入到数组b中。(1)当遍历到数组a的第一个元素的时候,就将这个元素放入到b数组中,以后遍历到的元素都和已经放入到b数组中的元素进行比较;(2)如果比b数组中的每个元素都大,则将该元素插入到b

jfhdd的博客 536

hdu 1025 Constructing Roads In JGShining's Kingdom (最长上升子序列)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 解题报告:刚开始想用二分匹配,但是二分匹配可以使线相交,明显不行; 其实这道题仔细挖掘,可以发现很多信息 !每个P都与唯一的一个r相连,每一个r都与唯一的p相连,就保证从1 到n的每个数都不会空着,就可以从1-----n来找富城市所对应的穷城市,穷城市之间的序号也从小到大即可加入dp

起航 579

hdu1025 Constructing Roads In JGShining's Kingdom(最长上升子序列 + 二分处理)

Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8812Accepted Submission(s): 2513 Problem De...

angtongyou1893的博客 233

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

Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19839    Accepted Submission(s): 5610 Proble

便纵有千种风情 389
上一篇: QDUOJ 93 - 分辣条(01背包)
下一篇: QDU 18 - 反转数字
Snakeflute
博客等级 码龄11年 14粉丝 172原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值