随笔分类 - 算法基础—前缀和/差分
摘要:链接:https://ac.nowcoder.com/acm/contest/11185/C 来源:牛客网 题目描述 给出一个正整数序列 [a1…an][a1…an] 以及定值 kk,每次可以选择一个区间 [l,r] (r−l+1≥k)[l,r] (r−l+1≥k),把这个区间内的 aiai 除以二
阅读全文
摘要:链接:https://ac.nowcoder.com/acm/contest/22352/I 来源:牛客网 题目描述 阿强采摘了一些苹果,并把他们分堆排成了一行,从左往右编号为第 1 … 𝑛 堆,其中第𝑖堆苹果有aiai个。 完美主义者阿珍看到这些苹果,觉得他们摆放的非常杂乱。她要求阿强进行如下
阅读全文
摘要:Problem Description Pixels in a digital picture can be represented with three integers (R,G,B) in the range 0 to 255 that indicate the intensity of th
阅读全文
摘要:给定一个二进制数组 nums , 找到含有相同数量的 0 和 1 的最长连续子数组,并返回该子数组的长度。 示例 1: 输入: nums = [0,1] 输出: 2 说明: [0, 1] 是具有相同数量0和1的最长连续子数组。 示例 2: 输入: nums = [0,1,0] 输出: 2 说明: [
阅读全文
摘要:While we enjoy chatting with friends on the internet, it is always annoying that we are overwhelmed by lots of messages in various chat groups. A grea
阅读全文
摘要:You are given two integer arrays a and b of length n. You can reverse at most one subarray (continuous subsegment) of the array 𝑎a. Your task is to r
阅读全文
摘要:今天,书店老板有一家店打算试营业 customers.length 分钟。每分钟都有一些顾客(customers[i])会进入书店,所有这些顾客都会在那一分钟结束后离开。 在某些时候,书店老板会生气。 如果书店老板在第 i 分钟生气,那么 grumpy[i] = 1,否则 grumpy[i] = 0
阅读全文
摘要:链接:https://ac.nowcoder.com/acm/contest/9985/D 来源:牛客网 题目描述 叶妹妹很喜欢玩石头,于是这天泽鸽鸽给她出了一道石子游戏,规则是这样的:有n堆石子排成一行,其中第i堆石子有ai个,叶妹妹可以选择做无数次这种操作:每次操作把连续相邻的k个石子堆中的每堆
阅读全文
摘要:在仅包含 0 和 1 的数组 A 中,一次 K 位翻转包括选择一个长度为 K 的(连续)子数组,同时将子数组中的每个 0 更改为 1,而每个 1 更改为 0。 返回所需的 K 位翻转的最小次数,以便数组没有值为 0 的元素。如果不可能,返回 -1。 假hard真medium。这种题一定是从一边开始处
阅读全文
摘要:A. Dense Array 数据范围很小可以直接枚举,对于每个间隔用while循环二倍二倍往里插。 #include <iostream> using namespace std; int a[55]; int main() { freopen("data.txt", "r", stdin); i
阅读全文
摘要:Gildong has an interesting machine that has an array 𝑎a with 𝑛n integers. The machine supports two kinds of operations: Increase all elements of a s
阅读全文
摘要:Kolya got an integer array a1,a2,…,an. The array can contain both positive and negative integers, but Kolya doesn't like 0 , so the array doesn't cont
阅读全文
摘要:Tokitsukaze has a sequence of length n, denoted by a . Tokitsukaze can merge two consecutive elements of a as many times as she wants. After each oper
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; int a[1005][1005] = {0}, n, m; int main() { int t; cin >> t; while(t--) { memset(a, 0, sizeof(a)); cin >
阅读全文
摘要:Vladimir would like to prepare a present for his wife: they have an anniversary! He decided to buy her exactly nn flowers. Vladimir went to a flower s
阅读全文
摘要:You are given a string s[1…n]s[1…n] consisting of lowercase Latin letters. It is guaranteed that n=2kn=2k for some integer k≥0k≥0 . The string s[1…n]s
阅读全文
摘要:Cuber QQ 长期在网络上与他人对线,一天,他发明了一台神奇的打字机。这台打字机只能处理由 a,b,X 构成的字符串。具体来说,打字机能够执行如下三种操作。 • 操作1:将任意一个 X 替换为 aX 。 • 操作2:将任意一个 X 替换为 aXbX 。 • 操作3:删除任意一个 X 。 打字机启
阅读全文
摘要:Shubham has a binary string ss. A binary string is a string containing only characters "0" and "1". He can perform the following operation on the stri
阅读全文
摘要:https://ac.nowcoder.com/acm/contest/5758#description 做的迟了+只会水题.jpg 剩下的咕咕咕慢慢补 A. 题目描述 这里有一棵树,每个点和每条边都存在一个价值。对于树上点对的价值,包括点对的起点和终点以及路径上边权值之和,不包括路径上其他点值。
阅读全文
摘要:You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in
阅读全文