Codeforces 915B (Browser)

Ubuntu桌面消失?可能是lightdm配置在捣鬼:详细解析/etc/lightdm.conf的优先级机制与实战修复 本文详细解析了Ubuntu系统因lightdm显示管理器配置错误导致桌面消失的问题。通过分析/etc/lightdm.conf的优先级加载机制,提供了从systemctl诊断、调试模式运行到实战修复配置语法错误(如缺失[Seat:*]组)的完整方案。文章还探讨了在系统无法启动时使用chroot或恢复模式进行高级救援,并对比了lightdm与gdm3在NVIDIA驱动环境下的不同表现,帮助用户高效恢复图形界面。 阅读详情

题目时空门

Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don’t belong to this segment as fast as possible.

Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab i, then she can move it to the tab max(i - 1, a) or to the tab min(i + 1, b)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab i, she can close all the tabs with indices from segment [a, i - 1] or from segment [i + 1, b]). In the aforementioned expressions a and b denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then a = 3, b = 6.

What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from l to r inclusive opened?

Input
The only line of input contains four integer numbers n, pos, l, r (1 ≤ n ≤ 100, 1 ≤ pos ≤ n, 1 ≤ l ≤ r ≤ n) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened.

Output
Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [l, r].

Examples
inputCopy
6 3 2 4
output
5
inputCopy
6 3 1 3
output
1
inputCopy
5 2 1 5
output
0
Note
In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.

In the second test she only needs to close all the tabs to the right of the current position of the cursor.

In the third test Luba doesn’t need to do anything.

题意:

路霸在网上冲浪,她打开了n个网页,她现在的鼠标停留在pos的位置上,现在有用的网页在区间【l,r】上,她现在想把没用的(也就是不在区间上的网页全部关掉)
她现在的步骤有:
1.左移
2.右移
3.将左边的网站全部关掉
4.将右边的网站全部关掉
每个步骤的权值为1
问你把那些不再区间内的网页全部关掉的最小的权值和为多少?

思路:

这个题目其实很简单,读懂了题意基本就会了。这无非就是两个区间的问题。有四种情况:
1.【l,r】是完全包含【1,n】的区间,这时候很明显输出 0//这里其实就是两个一样的区间我只是扩充上了负数
2. l<=1,这样只需要把右边的那些网页关掉就好 最小权值就是 abs(r-pos)+1//abs(r-pos)代表给出的区间移动到最右边 1代表将右遍无用的所有的网站关闭。
3. r>=n,这样只需把左边的那些网页关掉就好 最小权值就是 **abs(pos-l)+1 **//abs(pos-l)代表给出的区间移动到最左边 1代表将左边无用的所有的网站关闭。
4. 【l,r】是区间【1,n】的真子集,这样你需要判断她先移动到最左端l权值小 还是移动到最右端n权值小 min(abs(pos-l),abs(r-pos))
然后无论你移动到最左端最右端 你都需要将鼠标指针移动到相反的那端,所以要加上 r-l 同时你还进行了两次删除操作 再加 2
所以最后的最小权值是 min(abs(pos-l),abs(r-pos))+2+r-l

详情见代码:

//有n个网页节目,鼠标现在停留在pos位置上,问你将区间【l,r】以外的删除最少需要经过多少次
//可以进行的操作有:左移 右移 关闭左边所有网页 关闭右边所有的网页
//每个操作的权值都是1
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>

using namespace std;
const int N=1e5+10;


int main()
{
    ios::sync_with_stdio(false);
    int n,pos,l,r;
    while(cin>>n>>pos>>l>>r)
    {
        if(l<=1&&r>=n)//所有的数包含在给你的区间内
            cout<<"0"<<endl;
        else  if(l<=1&&r<n)//区间左端完全包含1
        {
            cout<<abs(r-pos)+1<<endl;
        }
        else if(r>=n&&l>1)//区间右边完全包含n
        {
            cout<<abs(pos-l)+1<<endl;
        }
        else if(r<n&&l>1)//区间【l,r】是【1,n】的真子集
        {
            cout<<min(abs(pos-l),abs(r-pos))+2+r-l<<endl;
        }

    }
    return 0;
}
5分钟搞定Google Custom Search API申请:从注册到获取CX Key全流程 本文详细介绍了如何快速申请和配置Google Custom Search API,从Google Cloud项目创建、启用计费、获取API Key,到在Programmable Search Engine控制台创建自定义搜索引擎并获取关键的CX Key,提供了全流程实战指南。文章还包含安全配置建议、API调用测试方法及前端与后端的集成代码示例,帮助开发者高效实现网站或应用的智能搜索功能。 阅读详情

相关推荐

Openbmc系列之自动化测试框架1

Openbmc作为当下BMC固件领域最流行的开源软件,具备从需求计划、开发、调试、测试、版本管理等完整的体系。在测试领域,Openbmc基于python的robotframework框架,实现Openbmc的自动化测试,为高效发布Openbmc版本提供有力支持。本文作为测试系列文档一,介绍Openbmc自动化测试虚拟Openbmc的环境搭建。

qq_20341747的博客 2109

Codeforces 915B Browser 分类找规律

题目描述: Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs t

Fluence_YHL 379

219页华为供应链管理:市场预测S&OP计划、销售预测与存货管理精要

S&OP计划的整合作用:S&OP是一种综合的销售和运营计划流程,它将市场预测、生产能力、库存水平和财务目标整合在一起,以确保企业能够平衡供需,实现最佳的运营效率。持续监控与改进:市场预测、S&OP计划、计划委员会的决策以及存货管理都需要持续的监控和评估。供应链策略与执行:华为ISC拥有清晰的供应链策略,并通过SISC架构实现了策略的有效执行,包括供应链网络设计、库存管理、物流优化等。持续的供应链创新:华为ISC不断探索新的供应链管理方法和技术,如数字化供应链、智能物流等,以适应全球化和市场的快速变化。

zuoan1993的博客 2433

B. Browser(模拟)

B. Browser time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Luba is surfing the Internet. She currently has n

sdau20163940的博客 444

在PyCharm中配置使用Anaconda环境

在PyCharm中配置使用Anaconda环境一、步骤1.Anaconda2.PyCharm总结 一、步骤 1.Anaconda 如未安装Anaconda可至其官网下载,学习使用个人版就可以了。 下载地址:https://www.anaconda.com/products/individual 1、打开Anaconda Navigator,点击Environments可以看到anaconda中已经有了默认的“base”环境,其中包含了大多数我们会用到的包,在PyCharm中可以直接使用该环境,而无需自行下载

TuckX的博客 19万+

DTI-ALPS处理笔记

前段时间刚好学习了一下DTI-ALPS处理(diffusion tensor image analysis along the perivascular space ),记录一下,以便后续学习。ALPS是2017年发表在《Japanese Journal of Radiology》的一篇文章首次提出的 (),主要用于无创评估脑内淋巴系统功能的衡量数值。C图和D图中的蓝色部分是投射纤维,绿色部分是联合纤维,红色部分是皮下纤维。

weixin_52073820的博客 4788

最小秒数

Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tab...

weixin_44020969的博客 330

海康威视iVMS-8700综合安防管理平台 文件读取漏洞复现

HIKVISION iVMS 综合安防管理平台download接口处存在任意文件读取漏洞,攻击者通过构造token绕过身份认证,读取服务器中的目录信息与敏感文件。使系统处于极不安全的状态。

0xSec 3304

Browser CodeForces - 915B

Browser CodeForces - 915B Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at th

codeswarrior的博客 486

基于Simulink的双PMSM差速驱动转矩同步控制建模示例

本文详细介绍了基于Simulink的双永磁同步电机(PMSM)差速驱动转矩同步控制建模方法。针对AGV/叉车等双电机独立驱动系统的转矩不同步问题,提出主从式+交叉耦合控制策略,在Simulink中实现直线行驶、90°转弯和单轮打滑恢复三种工况的仿真验证。通过动力学建模、参数差异设置、同步误差定义及控制律设计,最终实现同步误差<3%、转弯半径跟踪误差<5%、打滑后100ms内恢复的性能指标。文章特别强调了实际工程中的参数标定、通信同步和故障处理要点,并提供了完整的Simulink建模步骤和工具箱使

xiaoheshang_123的博客 203

PCL 均匀采样【2026最新版】

根据输入点云数据创建一个微小的三维立方体集合,然后计算每个三维立方体的重心;由于该重心点不一定是原始点云中的点,直接用该点来表示立方体内所有的点会丢失原始点云的细小特征;所以使用k最近邻搜索寻找距离重心点最近的原始点来代替重心点。

点云侠的博客 41万+

codeforce 915 B Browser

Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tab

toby的博客 783

【Python爬虫(90)】以Python爬虫为眼,洞察金融科技监管风云

本文聚焦爬虫技术在金融科技监管中的应用。开篇阐述金融科技发展带来监管挑战,引出爬虫技术的重要性。接着介绍金融科技监管政策与合规要求,包括政策法规体系、合规细则及政策变化应对。随后探讨爬虫技术选型、数据监测策略、风险指标抓取及案例实操。还阐述基于爬虫数据构建风险预警与防控机制,含模型构建、阈值设定等。最后总结爬虫技术应用成果,展望其与人工智能融合、适应新监管需求及重视数据安全的未来发展趋势。

邓邓子的博客 1063

CodeForces - 915B Browser (模拟)

题目链接:http://codeforces.com/problemset/problem/915/B点击打开链接 B. Browser time limit per test 1 second memory limit per test 256 megabytes input standard input output standard

xuejye的博客 473

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

CodeForces - 915B Browser

B. Browser time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Luba is surfing the Internet. She currently has n

Lngxling的博客 404

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

915B. Browser

B. Browser time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Luba is surfing the Internet. She currently has n

memory_qianxiao的博客 815

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Browser

Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tab

非人类浩的博客 471

B - Browser

Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tab...

年轻过成了秃顶 292

X303 2018 10 8 课程总结

一.初步认识JAVA 1.了解电脑程序:程序就是一系列动作的执行过程,电脑也是如此 2.JAVA的广泛应用:游戏,银行ATM都应用了JAVA技术 二.如何安装JAVA jdk环境变量配置: JAVA_HOME: C:\Program Files\Java\jdk1.8.0_91 CLASSPATH:C:\Program Files\Java\jdk1.8.0_91\lib PATH: C:\P...

zhangs992的博客 275

B-browser

B. Browsertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLuba is surfing the Internet. She currently has n opened tabs in her browser, indexed fro

qq_40129237的博客 380

Educational Codeforces Round 36 (Rated for Div. 2) A-C

期末考试前   折腾折腾 A: A. Garden time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Luba thinks about w

Sizaif's 小屋 566

2018/8/18(补题)

一: CodeForces - 915B  Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. L...

qq_40214483的博客 483

Browser 重流和重绘

浏览器的核心是两部分:渲染引擎和 JavaScript 解释器(又称 JavaScript 引擎)。 渲染引擎 渲染引擎的主要作用是,将网页代码渲染为用户视觉可以感知的平面文档。 不同的浏览器有不同的渲染引擎。 Firefox:Gecko 引擎 Safari:WebKit 引擎 Chrome:Blink 引擎 IE: Trident 引擎 Edge: EdgeHTML 引擎 渲染引擎处理网页,...

雾里看花叹朦胧 545

Codeforces 939A Love Triangle(三角恋问题)

题目:As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are n planes on Earth, numbered from 1 to n, and the plane with number i like

Puppet__的博客 1315

Codeforces 932A Palindromic Supersequence (超级水)

题目:You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B.A subsequence of a string is a string that can be derived from it by deleting some (not necessarily con

Puppet__的博客 993

CodeForces 875B ( Sorting the Coins) 难度蛮大的一道题目 题目说了一堆主要还是找规律

B. Sorting the Coins time limit per test: 1 second memory limit per test: 512 megabytes input: standard input output: standard output Recently, Dima met

Puppet__的博客 910
上一篇: Codeforces 919A (Supermarket)
下一篇: Codeforces 908A (New Year and Counting Cards)914A(Perfect Squares)
Puppet__
博客等级 码龄9年 319粉丝 328原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值