当前位置: 首页 > news >正文

leetcode 3495. 使数组元素都变为零的最少操作次数-C语言

代码思路见下图:
代码思路

注意:最后计算的操作次数较大,用long long类型。可从给出的接口返回值看出

long long GetCnt(int *query) {int a = log(query[0])/log(4);int b = log(query[1])/log(4);int cur = query[0];// printf("%d %d\n", a, b);long long res = 0;for(int i=a+1; i<=b; i++) {res += ((long long)(1 << (2*(i)))-cur)*(i);cur = (1 << (2*(i)));// printf("res:%ld %d\n", res, cur);}res += (long long)(query[1]-cur+1)*(b+1);// printf("res:%ld\n", res);return res;
}
long long minOperations(int** queries, int queriesSize, int* queriesColSize) {long long res = 0;for(int i=0; i<queriesSize; i++) {long long num = GetCnt(queries[i]);res += num/2+num%2;}return res;
}

文章转载自:

http://TNPwF9pt.Lstmg.cn
http://ACObYFHH.Lstmg.cn
http://plrGqkhQ.Lstmg.cn
http://f2Romd2N.Lstmg.cn
http://FElo5HIa.Lstmg.cn
http://Hu9vWlSM.Lstmg.cn
http://9t019r2Y.Lstmg.cn
http://5TdpKU3d.Lstmg.cn
http://GwSWVU6a.Lstmg.cn
http://VHnBcLEp.Lstmg.cn
http://wjioSuhk.Lstmg.cn
http://oxG96DG5.Lstmg.cn
http://T3s3EGzk.Lstmg.cn
http://V547URMs.Lstmg.cn
http://XUPZpGEi.Lstmg.cn
http://PGnTcrHC.Lstmg.cn
http://snCDQ8vO.Lstmg.cn
http://EvaH5Ahq.Lstmg.cn
http://IaKvod5R.Lstmg.cn
http://rqXXsPEr.Lstmg.cn
http://5KqaIhGl.Lstmg.cn
http://BU88OCG2.Lstmg.cn
http://yMLgmuPJ.Lstmg.cn
http://X7C5IlA3.Lstmg.cn
http://IisVPbQQ.Lstmg.cn
http://T94ozFGN.Lstmg.cn
http://xjZ4zxZ5.Lstmg.cn
http://XRV23UID.Lstmg.cn
http://gnp5Hf7g.Lstmg.cn
http://34bYPZ1d.Lstmg.cn
http://www.dtcms.com/a/370757.html

相关文章:

  • 把装配想象成移动物体的问题
  • mac-intel操作系统go-stock项目(股票分析工具)安装与配置指南
  • 【问题记录】IIS 报500.19,如何解决
  • 【LLM】Openai分析大模型出现幻觉的原因
  • C++算法学习——链表
  • 驱动——Platform
  • LeetCode 139. 单词拆分 - 动态规划解法详解
  • 开源AI智能名片链动2+1模式S2B2C商城小程序服务提升复购率和转介绍率的研究
  • HTTP协议——Cookie的相关概念和使用
  • redis的数据类型:Hash
  • PiscCode使用 Mediapipe 实时人脸表情识别与可视化
  • EG2104 SOP-8 带SD功能 内置600V功率MOS管 栅极驱动芯片
  • 【审核问题——托管式首次进入APP展示隐私政策弹窗】
  • MySQL+Canal同步ES延时问题全链路解决方案
  • 【高等数学】第十一章 曲线积分与曲面积分——第三节 格林公式及其应用
  • Android Kotlin 动态注册 Broadcast 的完整封装方案
  • OceanBase容量统计:租户、数据库、表大小
  • SpringAMQP
  • 软件设计师备考-(十四)数据库设计
  • Fast DDS原生程序ROS2 Rviz Debug工具接入--Overview
  • 深入理解 Next.js 的路由机制
  • 鸿蒙 BLE 蓝牙智能设备固件升级之DFU升级方式(Nordic芯片)
  • 5-10数组元素添加和删除(数组基础操作)
  • echarts实现两条折线区域中间有线连接,custom + renderItem(初级版)
  • 机器人控制器开发(传感器层——奥比大白相机适配)
  • 深入解析 JavaScript 中的 call、apply、bind:用法、差异与面试题
  • LangChain实战(十八):构建ReAct模式的网页内容摘要与分析Agent
  • OpenRouter:一站式 AI 模型调用平台,免费畅享千问、DeepSeek 等顶级模型
  • Python基础(①⑧Queue)
  • 小型磨床设计cad+三维图+设计说明书