A1044 Shopping in Mars(25)-二分

PAT甲级 1044 Shopping in Mars 【代码】PAT 1044 Shopping in Mars。 阅读详情

本题题意是通过计算中间连续整数和是否定值相同得到一个范围,可以直接利用upper_bound函数解决,因为数均为正整数,所以可以将将sum[i]定义为i及i以前的数之和,那么相减就能得到连续和的数啦

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=100010;
int main()
{
	int sum[maxn]={0};
	int n,m,temp,tempm;
	cin>>n>>m;
	tempm=100000010;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&sum[i]);
		sum[i]+=sum[i-1];
	}
	for (int i=1;i<=n;i++)
	{
		int j=upper_bound(sum+i,sum+n+1,m+sum[i-1])-sum;
		
		if(sum[j-1]-sum[i-1]==m)
		{
			tempm=m;
			break;
		}
		else if(sum[j]-sum[i-1]<tempm&&j<=n)
		{
			if(sum[j]-sum[i-1]>m)
			tempm=sum[j]-sum[i-1];
		}
	}
	for (int i=1;i<=n;i++)
	{
		int j=upper_bound(sum+i,sum+n+1,tempm+sum[i-1])-sum;
		if(sum[j-1]-sum[i-1]==tempm)
		{
			printf("%d-%d\n",i,j-1);
		}	
	}
}
LVGL8.x 实体按键与Keypad驱动的无缝对接实战 本文详细解析了LVGL8.x中实体按键与Keypad驱动的两种对接方案:坐标映射的Button方式与事件驱动的Keypad方式。重点阐述了如何模块化裁剪lv_port_indev.c模板文件,并深入讲解了Keypad驱动与Group焦点管理系统的核心协作机制,为无触摸屏的嵌入式设备提供流畅的UI交互解决方案。 阅读详情

相关推荐

DEXPI与Proteus XML:解锁过程工业P&ID数据互操作性的技术核心

本文深入探讨了DEXPI与Proteus XML在过程工业P&ID数据互操作性中的核心技术。通过解析DEXPI标准的开源特性和Proteus XML的架构设计,揭示了其在跨平台数据交换中的关键作用,并结合CADMATIC和西门子COMOS的实战案例,展示了如何实现高效的数据集成与转换。

weixin_29195615的博客 386

PAT A1044 Shopping in Mars (25 分) 二分

题目大意:给出一个正数序列,在当中找到满足这样条件的连续子串:子串的和大于等于给定值。输出具有最小的和的子串的开始和结束位置的下标(从1开始计),如果这样的子串有两个以上,按照开始位置从小到大,输出所有子串的开始和结束位置。 一开始直接暴力遍历所有子串,并维护最小的子串和。但这样还是有两个测试点超时,开始位置肯定是需要遍历序列的每个元素的,那么减少耗时的主要方法就是如何查找结束位置,问题就转换为...

HackingGate的博客 446

【腹腔镜数据集】Cholec80+CholecSeg8k2020+Endoscapes2024

计算机辅助手术的发展旨在提高手术的正确性和安全性。然而,研究人员和工程师却面临着开发和训练更好算法所需的注释数据有限的问题。因此,同步定位与建图(SLAM)等基础算法的发展受到限制。基于Cholec80数据集,从Cholec80中的17个视频片段中提取了8,080个腹腔镜胆囊切除术图像帧,对图像进行注释并向公众发布。该数据集名为 CholecSeg8K。这些图像中的每一个都以十三个类别的像素级注释,这些类别通常在腹腔镜胆囊切除术中发现。

Toky_min的博客 2024

pat 甲级 二分 A1044 Shopping in Mars (25分)

1044 Shopping in Mars (25分) Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of t

weixin_42358356的博客 126

Bellhop水声信道模型的仿真

Bellhop是一种基于射线追踪的水声信道模型,广泛用于预测水下环境中的声压场。它通过模拟声波在水中的传播路径,计算声场分布,适用于复杂的水下通信场景。

yt94832的博客 1315

手把手教你用Ubuntu 22.04的附加驱动工具安装NVIDIA显卡驱动(含常见错误修复)

本文详细介绍了在Ubuntu 22.04系统上,如何通过图形化的“附加驱动”工具安全、便捷地安装NVIDIA显卡驱动。内容涵盖从准备工作、禁用默认的nouveau驱动、图形界面安装实操,到安装后的验证(如使用nvidia-smi命令),并提供了安装失败黑屏、亮度调节失效等常见问题的深度解决方案,帮助用户彻底搞定驱动安装难题。

weixin_29248653的博客 604

4.5 PAT A1044 Shopping in Mars (25分)(二分;动态规划)

1044 Shopping in Mars (25分) Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chai...

小魚兒 213

13、核心网络模块:VyOS 设备配置实战

本文详细介绍了如何使用 Ansible 核心网络模块对 VyOS 虚拟设备进行自动化配置,涵盖环境搭建、变量设置、任务编写、playbook 运行及配置验证全过程。通过实际案例展示了 Ansible 在网络设备管理中的强大功能,包括多设备支持、模板化配置、备份回滚等优势,并提供了最佳实践建议与未来发展趋势分析,帮助读者提升网络运维效率。

linux6sysadmin的博客 114

A1044 Shopping in Mars (25 分| 二分查找| upper_bound,附详细注释,逻辑分析)

写在前面 实现思路 测试用例 input: output: ac代码 学习代码

kngines 289

QGIS将经纬度坐标转成点

QGIS绘制一张地图

weixin_46713695的博客 6056

Spring Boot入门(03): 从零开始学习配置文件:掌握YAML和Properties,轻松应对多环境配置管理

在Spring Boot开发中,配置文件是非常重要的。本文将带领你从零开始学习配置文件,掌握YAML和Properties的语法,轻松应对多环境配置管理。无论是开发、测试还是生产环境,你都可以轻松切换不同的配置文件,并且能够灵活修改配置信息。

**My Coding Family** 4万+

PAT (Advanced Level) Practice A1044 Shopping in Mars (25 分)(C++)(甲级)(二分法)

1044 Shopping in Mars (25 分) Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chai...

izhxxx的博客 347

ARFoundation系列讲解 - 24 锚点

一、添加平面检测和平面可视化 请参考 ARFounnation快速入门-08平面检测 案例 二、添加射线检测 1.在AR Session Origin 组件上添加ARRaycastManager 脚本

a451319296的博客 4882

A1044 Shopping in Mars (25 分)(求序列中所有和值大于或者等于S的连续子序列)(二分)

Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position ...

julia7_的博客 347

visio安装包

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

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

[PAT A1044]Shopping in Mars

[PAT A1044]Shopping in Mars 题目描述 1044 Shopping in Mars (25 分)Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). W...

欢迎来到我的编程小屋 651

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

PAT甲级 1044 Shopping in Mars (25分)

PAT甲级 1044 Shopping in Mars (25分) 这种狗屎的,只卡一个点,又不知道这个点是什么数据什么情况,还要自己取揣测,真难受! 本人代码附上 采用前后指针法,暴力解题! #include <iostream> #include <map> #include <vector> #include <algorithm> #include <cstring> #include <string> using names

一棵小白菜的博客 244

SAP B1中文培訓教材_SDK

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

PAT 1044 1044 Shopping in Mars (前缀和+二分)

【代码】PAT 1044 1044 Shopping in Mars。

weixin_50679551的博客 924

PAT-A-1044 Shopping in Mars 【二分查找】 【前缀和】

Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of the diamonds are taken off the

gdc6916的博客 2万+

【PAT1044】Shopping in Mars 二分法

1044. Shopping in Mars (25) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Shopping in Mars is quite a different exp

天堂人间 2994

A1044 Shopping in Mars (25)

GPLT A1044 Shopping in Mars (25)

NEFU AB-IN's Blog 506

1044 Shopping in Mars

1044 Shopping in Mars (25 point(s)) 题意 给一串 数字 找出大于 给定值 pay 的一些数字从I到j的组合 思路1 ​ 动态规划 ​ #include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;vector&gt; #include &lt;algorithm&gt; #define MAX 100...

sologala的博客 296

PAT甲级.1044. Shopping in Mars (25)

题意 Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M). When making the payment, the chain can be cut at any position

R11happy的博客 724

PAT A1044 Shopping in Mars

PAT A1044 Shopping in Mars Sample Input 1: 16 15 3 2 1 5 4 6 8 7 16 10 15 11 9 12 14 13 Sample Output 1: 1-5 4-6 7-8 11-11 Sample Input 2: 5 13 2 4 5 7 9 Sample Output 2: 2-4 4-5 word meaning...

qq_42347617的博客 193

【PAT】A1044 Shopping in Mars【二分查找】

Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position ...

elegant coder 903

PAT A1044 Shopping in Mars二分

Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position ...

qq_36525099的博客 165

PAT 1044 Shopping in Mars(二分查找)

一直以来以为自己算法虽然不行,总不至于连二分都不会了。今天看操作系统,看到文件系统那,看到二分相关的知识点,偶然想练练,没想到一练习自己吓一跳,我还真忘记怎么写二分了…但看了看还是很快知道了。 (吐槽一下,这题要扫两边,开始只扫了一遍,看二分去了忘记题目有存在不匹配的情况,牛客网那倒是过了,因为它那根本就没有不匹配的情况…但也不是啥大问题,想清楚就很好写了) 链接:PAT 1044 Shopping in Mars 题目 Shopping in Mars is quite a different exper

RobinWitch的博客 514
上一篇: A1010(25)二分法解决进制匹配问题
下一篇: A1048 Find Coins (25)二分
coder_Kim
博客等级 码龄8年 2粉丝 160原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值