cf599C Day at the Beach(区间合并)

百度api爬虫(1)从百度api中爬取地点数据 几句废话———— 百度api就是基于百度地图的开发接口,这么大的地图公司居然给开发接口真的很感激哎! 所以,言归正传。现在项目需求要把乌鲁木齐市内的所有清真寺都用矢量圈出来,然后做点统计啥的,最后做个专题图产品。 怎么把清真寺找出来? 领导的意思是你一个一个上网搜吧,这就是你的工作量。那我当然要想办法啊,边工作边学习工作才有意义嘛! 然后就发现百度api可以实现我的需求。其实可以通过py... 阅读详情

C. Day at the Beach
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles.

At the end of the day there were n castles built by friends. Castles are numbered from 1 to n, and the height of the i-th castle is equal to hi. When friends were about to leave, Squidward noticed, that castles are not ordered by their height, and this looks ugly. Now friends are going to reorder the castles in a way to obtain that condition hi ≤ hi + 1 holds for all i from 1 to n - 1.

Squidward suggested the following process of sorting castles:

Castles are split into blocks — groups of consecutive castles. Therefore the block from i to j will include castles i, i + 1, …, j. A block may consist of a single castle.
The partitioning is chosen in such a way that every castle is a part of exactly one block.
Each block is sorted independently from other blocks, that is the sequence hi, hi + 1, …, hj becomes sorted.
The partitioning should satisfy the condition that after each block is sorted, the sequence hi becomes sorted too. This may always be achieved by saying that the whole sequence is a single block.
Even Patrick understands that increasing the number of blocks in partitioning will ease the sorting process. Now friends ask you to count the maximum possible number of blocks in a partitioning that satisfies all the above requirements.

Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day.

The next line contains n integers hi (1 ≤ hi ≤ 109). The i-th of these integers corresponds to the height of the i-th castle.

Output
Print the maximum possible number of blocks in a valid partitioning.

Sample test(s)
input
3
1 2 3
output
3
input
4
2 1 3 2
output
2
Note
In the first sample the partitioning looks like that: [1][2][3].
这里写图片描述

In the second sample the partitioning is: [2, 1][3, 2]
这里写图片描述

就是给一个序列,然后划分区间,每个区间自己排序之后的结果和整体排序的结果是一样的,问最多划分多少区间。

当时按照区间的思想想了一下,每个数排序之后都是有位置的,那么这个数现在的位置到排序后的位置就是这个数的最短区间。
然后猜想一下(因为有的数会有多个)
找出这个数的上下界up,down
1.如果现在位置在上下界内,区间就是[i,i];
2.如果在下界以下,就是[i,down];
3.上界以上,就是[up,i];
然后得到n个区间,接着区间合并,看有多少个独立区间。

当时没有完整证明出来,现在还是想不通,只能从yy角度上想通一点,找了半天也没有反例,而且终测也过了,看样应该有道理,再想想吧。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
int a[100005],b[100005];
struct Node
{
    int l,r;
}node[100005];
bool cmp(Node a,Node b)
{
    if(a.l == b.l)return a.r < b.r;
    return a.l < b.l;
}
int main()
{
    #ifdef LOCAL
    freopen("C:\\Users\\ΡΡ\\Desktop\\in.txt","r",stdin);
    //freopen("C:\\Users\\ΡΡ\\Desktop\\out.txt","w",stdout);
    #endif // LOCAL
    int n;
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)
        scanf("%d",&a[i]);
    for(int i = 1;i <= n;i++)b[i] = a[i];
    sort(b + 1,b + 1 + n);
    for(int i = 1;i <= n;i++)
    {
        int down = lower_bound(b + 1,b + 1 + n,a[i]) - b;
        int up = upper_bound(b + 1,b + 1 + n,a[i]) - b - 1;
        if(down <= i &&i <= up)node[i].l = node[i].r = i;
        else if(i < down)
        {
            node[i].l = i;node[i].r = down;
        }
        else
        {
            node[i].r = i;node[i].l = up;
        }
    }
    /*for(int i = 1;i <= n;i++)
        cout<<node[i].l<<" "<<node[i].r<<endl;*/
    sort(node + 1,node + 1 + n,cmp);
    int ans,l,r;
    ans = 1;l = node[1].l;r = node[1].r;
    for(int i = 2;i <= n;i++)
    {
        if(node[i].l > r)
        {
            ans++;l = node[i].l;r = node[i].r;
        }
        else
            r = max(r,node[i].r);
    }
    printf("%d\n",ans);
    return 0;
}
避开PFC设计大坑:从环路分析到参数整定的5个常见误区与解决方案 本文深入解析PFC电路设计中从环路分析到参数整定的5个常见误区,包括电感参数设计、小信号模型适用边界、电压环与电流环耦合效应等。通过实际案例和PSIM仿真数据,提供工程落地的解决方案,帮助工程师避开设计陷阱,提升电路性能与可靠性。 阅读详情

相关推荐

Vivado与VCS+Verdi联合仿真环境搭建全攻略

本文详细介绍了如何搭建Vivado与VCS+Verdi联合仿真环境,旨在解决Vivado Simulator在大型FPGA验证中速度慢、调试弱的问题。通过指导工具版本配对、环境变量设置、关键参数配置及Xilinx仿真库编译,帮助工程师高效整合Vivado的设计管理、VCS的高速仿真与Verdi的深度调试能力,从而显著提升验证效率。

weixin_29219189的博客 576

21、详解柔性数组

本文详细解读了C语言中的柔性数组,读完这篇文章一定可以掌握

xjtuxinghy的博客 142

海思Hi3519AV100 sensor移植实战:IMX586驱动调试与硬件验证全流程

本文详细解析了在海思Hi3519AV100平台上移植索尼IMX586传感器的全流程实战。内容涵盖从硬件I2C通信验证、驱动代码移植与修改,到内核配置、时钟设定,以及使用示波器进行硬件信号深度验证和ISP图像调优等关键步骤,为开发者提供了一套清晰、可复现的sensor移植与调试方法。

weixin_29168393的博客 395

Codeforces Round #332 (Div. 2) C. Day at the Beach

C. Day at the Beach time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Squidward, Spongebob and Patric

ZZ_AC的博客 709

重装系统后,恢复Oracle的.ORA文件

前几天,系统莫名奇妙产生很多宏病毒,进而感染整个C盘,不得已,格式化后重装了系统。 重装系统之后,突然想到D盘中的oracle中很多数据没导出来备份,安装文件下有很多有用的.ORA文件,抱着死马当活马医的态度,居然成功了。 1、将原来D盘(D:\oracle\product\10.2.0\oradata\orcl)下的数据文件备份下其他盘,将D盘的oracle目录名改成oracle1。安装数据

zhanggnol的blog 5551

CST入门——0. 安装CST Studio Suite 2022

安装CST Studio Suite 2022详细操作步骤

plmxu34的博客 6万+

Codeforces 599C Day at the Beach【思维+优先队列】

C. Day at the Beach time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Squidward, Spongebob and Patrick decided

mengxiang000000 525

RV1126 MIPI CSI-2驱动RGB888图像采集的V4L2实战解析

本文详细解析了在RV1126平台上通过MIPI CSI-2接口采集RGB888格式图像的完整V4L2实战流程。核心内容包括设备树(DTS)配置、内核驱动适配、Media Controller链路调试,以及使用v4l2-ctl工具进行图像抓取与验证的方法,旨在帮助开发者打通从硬件连接到稳定采集RGB888图像数据的关键环节。

weixin_29161719的博客 166

Sum Balance,CF1242C,找环+状态压缩Dp

正题 首先只能交换一次,我们给一个点向丢弃这个点能换来的点连有向边,那么问题就变成了,找到一些环,使得每个集合中只有且仅有一个点在环上,首先可以证明这是一棵基环内向树森林,因为每一个点的出度,在题解中也说到了这是一个"function graph",不可能有两个环有公共点,所以我们直接找强连通分量,注意这里的不能把单点但没有自环的强连通分量算进去,因为不能构成一种方案,如果强连通分量...

Deep_Kevin的娱乐空间 412

Ubuntu开机进入initramfs,解决办法来了!

摘要:Ubuntu系统启动时卡在initramfs界面,表明系统无法正常挂载根文件系统。常见原因包括引导配置错误、文件系统损坏、驱动程序问题和硬件故障。解决方法包括:1)使用fsck修复文件系统;2)通过dmesg排查驱动问题;3)检查硬盘等硬件状态;4)重新安装GRUB引导程序。建议做好系统备份等预防措施,遇到问题时按步骤排查。该问题通常可通过文件系统修复或引导配置重建解决。(148字)

米可的博客! 3419

小孙学变频学习笔记(二)变频器的逆变电路

本文主要介绍了变频器中逆变电路的核心器件IGBT及其应用。IGBT是一种电压控制型三端半导体开关器件,具有开关频率高、功耗低的优点,在变频器中仅使用截止和饱和导通状态。文章详细分析了IGBT的结构特性、与晶闸管的区别,以及由四个IGBT组成的直流转交流逆变电路原理。重点阐述了IGBT并联反向二极管的作用:提供电流反向通路、避免反向电压损坏器件、提高开关效率等。最后提供了相关学习参考网址供读者进一步研究。

qq_43091070的博客 1195

CF- Day at the Beach

C. Day at the Beach time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Squidward, Spongebob and Patrick ...

weixin_34356555的博客 144

电路布局中近场耦合问题

开关电源EMC设计中,传导骚扰超标往往源于空间耦合而非参数问题。某案例中,DC-DC模块的非屏蔽电感磁场泄漏耦合到邻近X电容,导致0.5MHz频点超标。通过将X电容移至PCB底层、优化布局保持15mm间距后,问题完全解决。实践证明:EMC设计需注重空间隔离,优先采用屏蔽电感,滤波元件应远离高频磁场区,布局优化比参数调整更有效。这提示工程师需将电磁兼容视为空间问题而不仅是电气问题。

硬核科技 375

Codeforces 599C Day at the Beach

题目链接:http://codeforces.com/problemset/problem/599/C 题意:给出大小为n的序列,要求将该序列分成连续的若干个部分,每个部分各自升序排序后组成的序列与原序列升序排序后一样,问最多分成几个部分 思路: 一开始可以想到要满足max(h1,h2,h3……,hx)max(h1,h2,h3……,hx),所以max[1,x]必定小于max[x

csdn364988181的博客 692

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

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

607A Chain Reaction(DP)

There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction

Techay的博客 1019

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

cf599D Spongebob and Squares(推公式,枚举)

Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisti

Techay的博客 935

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

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

Caesar's Legions(记忆化搜索)

Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had n1 footmen and n2 horsemen. Caesar thought that an arrangement is not beautiful if somewhere in the line there

Techay的博客 731

Matrix

You have a string of decimal digits s. Let’s define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in

Techay的博客 712

Dreamoon and WiFi

 Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the foll

Techay的博客 675

Cut Ribbon

 Cut Ribbon time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Polycarpus has a ribbon, its length is n.

Techay的博客 602

ZgukistringZ

 Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one. GukiZ has strings a, b, and c. He wants to obtain string k by swapping some l

Techay的博客 596

Writing Code(DP)

Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of

Techay的博客 590

Flipping Game

 Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Iahub got bored, so he invented a game t

Techay的博客 588

Ice Sculptures

 Ice Sculptures time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output The Berland University is preparing to

Techay的博客 568

Face Detection

Face Detection time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The developers of Looksery have to writ

Techay的博客 566

Maximum Absurdity(dp)

Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws

Techay的博客 547
上一篇: K Smallest Sums(优先队列+思维推广)
下一篇: cf599D Spongebob and Squares(推公式,枚举)
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值