HDU 1025 Constructing Roads In JGShining's Kingdom(最长递增子序列)

多普勒效应及多普勒频移的简单推导 多普勒频移的简单推导 阅读详情

Constructing Roads In JGShining's Kingdom

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 15   Accepted Submission(s) : 11
Font: Times New Roman | Verdana | Georgia
Font Size: ← →

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.

Author

JGShining(极光炫影)

point:
这是一题裸的最长递增子序列,但是要控制好输出格式。PE了好多次。格式题目里没有多提(或者我瞎),是每组输出后都要跟一个空行。

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
#define ll long long
int a[502000];
int main()
{
    int n;
    int p=0;
    while(~scanf("%d",&n))
    {
        p++;
        int b=n;
        while(b--)
        {
            int x;
            scanf("%d",&x);
            scanf("%d",&a[x]);
        }
        int now[502000];
        memset(now,0,sizeof now);
        int cnt=1;
        now[1]=a[1];
        for(int i=2; i<=n; i++)
        {
            if(a[i]>now[cnt])
            {
                cnt++;
                now[cnt]=a[i];
            }
            else
            {
                int k=lower_bound(now,now+cnt,a[i])-now;
                now[k]=a[i];
            }
        }
       //if(p!=1) printf("\n");
       if(cnt==1) printf("Case %d:\nMy king, at most %d road can be built.\n\n",p,cnt);
       else  printf("Case %d:\nMy king, at most %d roads can be built.\n\n",p,cnt);

    }


}


Python爬虫实战:Playwright 攻克京东图书新书榜(含动态价格与分页)! 我长期专注 Python 爬虫工程化实战,主理专栏 《Python爬虫实战》:从采集策略到反爬对抗,从数据清洗到分布式调度,持续输出可复用的方法论与可落地案例。内容主打一个“能跑、能用、能扩展”,让数据价值真正做到——抓得到、洗得净、用得上。 阅读详情

相关推荐

大漠多线程增强版:解决窗口消失、坐标错乱与识别卡死

多线程环境下窗口自动化面临的核心挑战,本质是GDI资源非线程安全、HWND生命周期失控及图像引擎状态污染三大底层问题。Windows GUI编程中,跨线程共享hDC、缓存失效的窗口句柄、OpenCV静态Mat等设计缺陷,导致FindPic失败、GetCursorPos异常、坐标跳变等典型故障。本方案通过线程局部存储(TLS)重构资源生命周期、WinEventHook+心跳探测构建实时窗口状态链、ABI对齐的多语言内存契约,实现稳定低延迟的并发UI识别与控制。适用于游戏多开监控、电商RPA、后台UI状态采集等

weixin_30561177的博客 477

hdu1025

import java.io.BufferedInputStream; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Scanner;

老李2009 640

STM32 DMA串口重定向printf:高效调试与性能优化实战

本文详细介绍了STM32 DMA串口重定向printf的实现方法与性能优势。通过对比传统方式的CPU高占用问题,阐述了DMA技术如何实现高效数据传输,大幅降低CPU负载。文章包含完整的代码实现、缓冲区管理技巧及实战调试方案,帮助开发者优化嵌入式系统调试效率。

lake5的博客 99

hdoj1025

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

◆◇丶生如夏花。谁来订阅我的悲伤 693

android mtk camera如何自定义默认拍照与录像分辨率

本文详细解析了在Android MTK平台上自定义相机默认拍照与录像分辨率的方法。通过分析Camera2应用默认选择逻辑,定位并修改PictureSize.java与VideoQualityCaptureRequestConfig.java中的关键代码,实现绕过系统智能选择,强制指定最高或特定分辨率。文章还提供了进阶的可配置化方案与验证避坑指南,帮助开发者精准控制相机行为。

weixin_29194817的博客 431

概述DeepLab系列(deeplab v1, deeplab v2, deeplab v3, deeplab v3+)

前言:图像分割是指像素级别的图像识别,即标注出图像中每个像素所属的对象类别。 语义分割更注重类别之间的区分,而实例分割更注重个体之间的区别。 DeepLab是由Google团队提出的一系列图像分割算法。 DeepLab v1 (2014年) Paper (ICLR 2015) Code 创新点: 空洞卷积(Atrous Conv); <解决编码过程中信号不断被下采样,细节丢失的问题> 全连接条件随机场(Fully-connected Conditional Random Field)。

ZSH12345678900的博客 5528

HDU 1025 Constructing Roads In JGShining's Kingdom (LIS 最长递增子序列)

【题目链接】:click here~~ 【题意】:河岸两旁有n个村庄,他们之间要互相修路,并且同一边的不互相修,在保证不交叉的情况下,最大限度的路的是多少。 【思路】转化题意后,发现是求LIS,入门题训练 LIS详细分析: 代码: /* * Problem: HDU No.1025 * Running time: 374MS * Complier: G++ * Author:

herongwei 的 BLOG 1300

五段式S型算法笔记

又因为有 v-v0= 0.5jt通式: 所以有 vm-v0= 0.5jtm 所以有4vm-4v0= 2jtm。算法1: v=2vm-v0-0.5*jt+2jt*tm-2jtm*tm。加加速度j 自己设置 已知,vmax自己设置已知;所以有4vm-4v0= 2jtm带入算法1。

qq_36658033的博客 681

HDU 1025(最长上升子序列)

Constructing Roads In JGShining’s Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description JGShining’s kingdom consists of 2n(n is no more t...

Eternally831143的博客 393

Android Activity面试题最全解析(5万字长文)

Intent是Android中用于启动活动、服务或广播的一种消息对象。它包含了一系列键值对数据,用于描述操作的目的以及需要传递的信息。IntentString:字符串intfloatlong:基本数据类型Parcelable:实现了Parcelable接口的对象:实现了接口的对象示例代码如下:Java深色版本1// 创建Intent并传递数据");67// 启动新的Activity是一个XML标签,用于定义ActivityService或可以响应的Intent类型。它包含了。

大模型大数据攻城狮的专栏 802

LLaMA Factory多卡微调的实战教程(持续更新)

本文主要介绍了LLaMA Factory多卡微调的实战教程(持续更新),希望对学习大语言模型的同学们有所帮助。 文章目录 1. 前言 2. 配置环境 2.1 安装虚拟环境 2.2 安装依赖库 2.3 模型选型与下载 2.4 配置多卡环境 3. 运行代码 3.1 构建训练数据 3.2 修改配置文件 3.3 微调 3.3.1 zero3微调 3.3.2 启动API 3.3.3 模型测试

herosunly的博客 25万+

mysql 错误代码

1.错误代码1025 因为涉及到外键,所以需要先删除外键约束,再删除外键列 我是想将表中某个元素的数据类型改掉 ALTER TABLE `s_course` MODIFY COLUMN `id` VARCHAR(18); 查询:alter table `s_course` modify column `id` varchar(18) 错误代码: 1025 Error on ren...

qq_41094265的博客 446

DRM全解析 —— encoder详解(3)

DRM全解析 —— encoder详解(3)

phmatthaus的专栏 490

hdu1025 Constructing Roads In JGShining's Kingdom(最长递增公共子序列二分法)

这题其实和1051是一个道理,以前看的别人的代码,现在看其实就是最长递增公共子序列的二分法。。。 5e5的数据量很显然普通方法不能,但是我今天才发现原来这就是二分法。。。 碉堡了。。。 #include #include #include #include using namespace std; const int N = 500005; const int INF = 1<<

Iguodala的博客 392

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

HDU1025 Constructing Roads In JGShining's Kingdom(最长递增子序列)

题目大意:求一列数的最长子序列;题目链接 题目解析:DP+二分 假设存在一个序列d[1..9] = 2 1 5 3 6 4 8 9 7,可以看出来它的LIS长度为5。 下面一步一步试着找出它。 我们定义一个序列B,然后令 i = 1 to 9 逐个考察这个序列。 此外,我们用一个变量Len来记录现在最长算到多少了 首先,把d[1]有序地放到B里,令B[1] = 2,就是说当只有1一

陌上花开 825

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Constructing Roads In JGShining's Kingdom(最长单调递增子序列应用+hdu1025)

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

寻找&星空の孩子 1762

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

hdu1025Constructing 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): 21561    Accepted Submission(s): 6105 Proble

338

[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: 65536/32768 K (Java/Others) Total Submission(s): 14635    Accepted Submission(s): 4158 Proble

逆风的方向 更适合飞翔 2261

[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: 65536/32768 K (Java/Others) Total Submission(s): 14635Accepted Submission(s): 4158 Pr...

weixin_33739627的博客 190

DP 60题 -2 HDU1025 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 cities are rich in resource (we call them rich ci...

日拱一卒,功不唐捐 3171

【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

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

【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

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): 16024    Accepted Submission(s): 4572 Problem

Alex 713

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

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 these cities are rich in resource (we call them rich

fanesemyk的博客 417
上一篇: HDU 1080 Human Gene Functions(LCS变形)
下一篇: HDU 4512 吉哥系列故事——完美队形I(最长公共上升子序列 LCIS)
Mr_Treeeee
博客等级 码龄10年 38粉丝 551原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值