ICode9

精准搜索请尝试: 精确搜索
  • LeetCode 1588 Sum of All Odd Length Subarrays 前缀和2022-09-15 17:30:19

    Given an array of positive integers arr, return the sum of all possible odd-length subarrays of arr. A subarray is a contiguous subsequence of the array. Solution 求所有奇数长度子序列的和。所以维护一个前缀和以后,我们只需要遍历间隔即可 点击查看代码 class Solut

  • POJ 1995 Raising Modulo Numbers 【Solution】(快速幂)2022-09-11 00:32:06

    [原题传送门](http://poj.org/problem?id=1995) 题目大意 先给定n组数据, 每组先给定m为模数, 再给定h组号码ai与bi, 输出每组数据处理的结果 题解 a^b的大小把握不住,从以下几点出发 1.考虑到求模公式:(ab)%p=(a%p)(b%p)%p 证明如下: 令a=k1p+r1,b=k2p+r2; 则(ab)%p=(k1k2pp+k1r2p+k2r1p+

  • 归程 | 学习《最优解的特征,一种在问题中发现观察的技术》博客2022-09-11 00:03:53

    前言 回到弃用许久的博客,第一件事情当然是浏览并删除黑历史啦。打算不再使用洛谷博客,感觉 2020 年 4 月左右本人就社死了,所以博客写这里应该还可以。感觉 OI 也许做不出什么成绩了,还剩两年,就允许我给这个美好的圈子留下一些痕迹吧。 介绍 原文传送门 最优性问题是算法竞赛中涉猎极

  • [Google] LeetCode 792 Number of Matching Subsequences2022-09-09 20:35:45

    Given a string s and an array of strings words, return the number of words[i] that is a subsequence of s. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative

  • 数位dp P3188 [HNOI2007]梦幻岛宝珠-Solution2022-09-01 21:30:44

    数位考虑+背包(+滚动数组) 首先,我们能发现,这是一道 \(n\) 很小但是体积和权值都非常大的背包。 但是这个题的体积有一个特殊的性质,就是他是 \(a\times 2^b,a\leq10\) 的形式,这个性质是非常好的。 我们定义 \(f_i\) 表示我们当前还剩 \(i\) 的空间我们能拿到的最大值,我们从大到小

  • 第46届ICPC EC final游记2022-08-29 23:05:14

    前言 因为在昆明区域赛中获得银首,高于csy,wh,zxh队和hzl,syr,tyy队,我队获得了EC名额。 此时我两个队友都决定退役了,所以这场比赛被当作了他们的最后一场比赛(然而后来又决定不退役了)。 这也是我的第一场线下XCPC(虽然在西安)。 Day -2(7.16) 因为宿舍不让住了,晚上跑到了校外和czq一起

  • 使用“环境变量”将系统config配置文件通过解决方案的方式进行迁移2022-08-29 11:01:58

    在CRM中我们通过会设置一些自定义的全局变量,例如第三方api的域名、任务启动的时间间隔、代理用户的配置等,但是在进行新环境部署的时候没法通过解决方案一次性导入,需要人为手动维护或者通过excel导入的方式,增加了迁移的时间成本 其实在PowerPlatform环境里有“环境变量”这样的配置

  • Solution - NOI 20222022-08-26 20:34:07

    游记 目前只有两个题题解(代码没有),啥时候数据出了我再来补剩下的。 众数 Solution 有个题叫「POI2014」Couriers,这个题启示我们实际上问题等价于询问哪个数出现次数最多,最后只需要判断是否超过一半即可。 考虑线段树,对于一个序列,开一棵线段树维护上面的权值,单个序列的查询可以在线

  • 519. 随机翻转矩阵 (hash 映射移动到最后)2022-08-25 23:02:56

      难度中等143收藏分享切换为英文接收动态反馈 给你一个 m x n 的二元矩阵 matrix ,且所有值被初始化为 0 。请你设计一个算法,随机选取一个满足 matrix[i][j] == 0 的下标 (i, j) ,并将它的值变为 1 。所有满足 matrix[i][j] == 0 的下标 (i, j) 被选取的概率

  • 青蛙跳台阶2022-08-24 23:34:13

    基础版 青蛙一次可以跳1级或者2级台阶,问跳到N级有多少种跳法 class Solution: def jumpFloor(self,n): if n < 1: return 0 if n == 1 or n == 2: return n a = 1 b = 2 tmp = 1 for i in range(2,n

  • 398. 随机数索引2022-08-24 23:33:12

      labuladong 题解思路 难度中等247收藏分享切换为英文接收动态反馈 给你一个可能含有 重复元素 的整数数组 nums ,请你随机输出给定的目标数字 target 的索引。你可以假设给定的数字一定存在于数组中。 实现 Solution 类: Solution(int[] nums) 用数组 nums 初始

  • [Oracle] LeetCode 696 Count Binary Substrings2022-08-24 06:31:01

    Given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively. Substrings that occur multiple times are counte

  • [Oracle] LeetCode 253 Meeting Rooms II2022-08-19 03:01:53

    Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required. Solution 先按照左端点排序的话,如果一个区间的右端点比下一个区间的左端点大,那么显然得额外新增一个房间。 注意到 \(map\)

  • Solution HTR003D2022-08-10 18:30:08

    50 分: 暴力枚举即可 100 分: 设输入的序列为 \(a_i\)。容易发现,如果我们按原序列从左往右扫,扫到第 \(i\) 个位置时,我们要考虑的是这一个位置要填什么以及 \(a_i\) 要填到哪个位置上。 并且一共只有 5 种情况: \(a_i\) 填到 \(i\) 上; 拿一个比 \(a_i\) 小的数填到 \(i\) 上并且 \(a_

  • Greedy Algorithm2022-08-10 16:30:25

    Greedy Algorithm A greedy algorithm is any algorithm that follows the problem-solving heuristic of making the locally optimal choice at each stage. In many problems, a greedy strategy does not produce an optimal solution, but a greedy heuristic can yield

  • Solution for CEOI20222022-08-05 00:31:58

    \(\cal T_1\) Abracadabra Description 给定长度为 \(N\)(保证为偶数)的排列,每次操作将排列对半分,然后做归并。\(Q\) 次询问,求 \(t\) 次操作后的第 \(i\) 张牌。 \(N\leqslant 2\cdot 10^5,Q\leqslant 10^6,0\leqslant t\leqslant 10^9\). Solution 一些闲话:黑心糖赛高! 可以发现归

  • LeetCode 713 Subarray Product Less Than K 滑动窗口2022-08-01 18:35:31

    Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than k. Solution 滑动窗口的思想。不断增大右端点 \(r\), 当乘积 \(pd\ge k\) 的时候,缩小左端点 \(l\),

  • LeetCode 204 Count Primes 欧拉(素数)筛2022-07-29 19:31:07

    Given an integer \(n\), return the number of prime numbers that are strictly less than \(n\). Solution 统计小于 \(n\) 的素数个数。这里用欧拉筛来筛素数,\(is\_prime\) 用来记录该数是否为素数,\(prime\) 来保存所有的素数 点击查看代码 class Solution { private: bo

  • LeetCode/外观数列2022-07-27 20:32:09

    给定一个正整数 n ,输出外观数列的第 n 项 「外观数列」是一个整数序列,从数字 1 开始,序列中的每一项都是对前一项的描述 1. 递归 判断相邻相等的方法每次只能处理上一个值 等价于每次比较上一个组的末位置与当前组的初始位置 最后一个值要额外处理 class Solution { public:

  • Solution Set - IQ ↓↓2022-07-17 21:17:16

    Q: 为什么说雨兔是个傻子? A: 因为一路上全是星号标记. 0. 「CF 1672H」Zigu Zagu *   Link & Submission & Tag:「C.性质/结论」   一个被忽略的方法——寻找操作前后变化形式优美的特征值.   假设对序列 \(S\) 操作, 设其中 \(00\) 子段的数量为 \(x\), \(11\) 子段的数

  • day212022-07-17 10:33:56

    1.剑指 Offer 15. 二进制中 1 的个数  与1同位与判断最低位是否是1,判断完右移继续判断下一个 1 class Solution { 2 public: 3 int hammingWeight(uint32_t n) { 4 int cnt = 0; 5 while(n){ 6 if(n & 1 == 1) cnt ++; 7 n >>=

  • LeetCode Median of Two Sorted Arrays 排序2022-07-10 03:00:08

    Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be \(O(\log (m+n))\). Solution 简单排序即可: 点击查看代码 class Solution { private: vector<int> vc;

  • 斐波那契数列2022-07-07 19:00:28

    为何什么用字典保存计算结果而不是列表? 使用字典的优势: 不必像使用列表一样提前分配内存 在字典中存入0,1对应的斐波那契数之后不必对0,1特殊处理 某个数是否算过的判断方式比列表更优雅 点击查看代码 class Solution: def fib_help(self, n, nb): if n < 2:

  • Aonynation 的连通性入门题目选讲2022-07-07 10:31:50

    因为是我做的 pdf 文件,所以就直接放 zip 的下载链接,题目很水。。。 安师大附中 Aonynation 交流课件 放一下源码。。。 \documentclass{beamer} \usepackage{ctex} \usetheme{default} \usecolortheme{spruce} \title{有关图连通性的入门讲解} \usefonttheme[onlymath]{serif}

  • 四数之和2022-07-06 18:04:09

       https://leetcode.cn/problems/4sum-ii/solution/si-shu-xiang-jia-ii-by-leetcode-solution/       时间复杂度和空间复杂度都是O(n2) func fourSumCount(a, b, c, d []int) (ans int) { mp:=make(map[int]int,0) for i:=0;i<len(a);i++{ for j:=0;j<

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有