STL
文章平均质量分 63
旺 崽
这个作者很懒,什么都没留下…
展开
-
LeetCode 525 连续数组
题目链接给定一个二进制数组 nums , 找到含有相同数量的 0 和 1 的最长连续子数组,并返回该子数组的长度。示例 1:输入: nums = [0,1]输出: 2说明: [0, 1] 是具有相同数量0和1的最长连续子数组。示例 2:输入: nums = [0,1,0]输出: 2说明: [0, 1] (或 [1, 0]) 是具有相同数量0和1的最长连续子数组。思维题~我们把 000 转化为 −1-1−1,然后求一遍前缀和,题目就转化为求一段和为 000 的区间的最大长度,用 ma原创 2021-06-03 19:22:25 · 6335 阅读 · 0 评论 -
Codeforces Round #644 (Div. 3) H.Binary Median
Codeforces Round #644 (Div. 3) H.Binary Median题目链接Consider all binary strings of length m (1≤m≤60). A binary string is a string that consists of the characters 0 and 1 only. For example, 0110 is a binary string, and 012aba is not. Obviously, there are ex原创 2020-05-26 15:33:17 · 10879 阅读 · 1 评论 -
牛客编程巅峰赛S1第11场 - 黄金&钻石 A.牛牛的01游戏
牛客编程巅峰赛S1第11场 - 黄金&钻石 A.牛牛的01游戏题目链接题目描述牛牛最近迷上了小游戏,于是他也想对他的01字符串进行一些操作,01字符串上的0和0相邻时会变成1,而1和1相邻时会在字符串上消失,而0和1相邻时什么都不会发生,牛牛现在把初始的字符串给你,你能告诉牛牛这个字符串最后会变成什么样吗。示例1输入"00110001"输出"01"简单模拟,就按题目要求来就行,注意一个坑点,两个 000 变成 111 后要判断答案字符串最后一位是否为 111,是的话直接删去即可原创 2020-08-14 09:10:46 · 2460 阅读 · 0 评论 -
智算之道初赛第二场 字符串
智算之道初赛第二场 字符串题目链接给定两个字符串 S 和 T,它们都只由小写字母组成。现在请计算出字符串 S 的本质不同的排列中有多少种是字符串 T 的子串。本质不同,就是看起来不同,例如 aab 有 33 种本质不同的排列 aab, aba, baa。输入格式第一行有一个字符串 S第二行有一个字符串 T输出格式输出一个整数表示字符串 S 的本质不同的排列中有多少种是字符串 T 的子串数据规模与约定对于 30% 的数据,1≤∣S∣≤5,1≤∣T∣≤2001 \leq |S| \leq 5原创 2020-07-20 10:56:50 · 2377 阅读 · 0 评论 -
2019牛客暑期多校训练营(第八场)G.Gemstones
2019牛客暑期多校训练营(第八场)G.Gemstones题目链接题目描述Gromah and LZR have entered the seventh level. There are a sequence of gemstones on the wall.After some tries, Gromah discovers that one can take exactly three successive gemstones with the same types away from the原创 2020-07-07 15:07:14 · 2364 阅读 · 0 评论 -
2019牛客暑期多校训练营(第七场)A.String
2019牛客暑期多校训练营(第七场)A.String题目链接题目描述A string is perfect if it has the smallest lexicographical ordering among its cyclic rotations.For example: “0101” is perfect as it is the smallest string among (“0101”, “1010”, “0101”, “1010”).Given a 01 string, you原创 2020-07-06 18:29:05 · 2324 阅读 · 0 评论 -
AtCoder Beginner Contest 157 E.Simple String Queries
AtCoder Beginner Contest 157 E.Simple String Queries题目链接Problem Statement(略)Constraints(略)Sample Input 17abcdbbd62 3 61 5 z2 1 11 4 a1 7 d2 1 7Sample Output 1315这题一开始以为是线段树,改了半天也...原创 2020-03-02 15:12:33 · 2653 阅读 · 2 评论 -
“新智认知”杯上海高校程序设计竞赛暨第十七届上海大学程序设计春季联赛 D.CSL 的字符串
“新智认知”杯上海高校程序设计竞赛暨第十七届上海大学程序设计春季联赛 D.CSL 的字符串题目描述CSL 以前不会字符串算法,经过一年的训练,他还是不会……于是他打算向你求助。给定一个字符串,只含有可打印字符,通过删除若干字符得到新字符串,新字符串必须满足两个条件:原字符串中出现的字符,新字符串也必须包含。新字符串中所有的字符均不相同。新字符串的字典序是满足上面两个条件的最小的字符串。...原创 2020-02-24 08:15:02 · 2657 阅读 · 0 评论 -
2020牛客暑期多校训练营(第三场)G.Operating on a Graph
2020牛客暑期多校训练营(第三场)G.Operating on a Graph题目链接题目描述You are given a graph containing n vertices and m edges. Vertices are numbered from 0 to n-1. Initially, vertex i belongs to group i. We define a group A is connected to group B if and only if there exists原创 2020-07-24 20:52:53 · 2357 阅读 · 0 评论 -
团体程序设计天梯赛 L2-009 抢红包
团体程序设计天梯赛 L2-009 抢红包题目链接没有人没抢过红包吧…… 这里给出N个人之间互相发红包、抢红包的记录,请你统计一下他们抢红包的收获。输入格式:输入第一行给出一个正整数 N(≤104)N(≤10^4 )N(≤104),即参与发红包和抢红包的总人数,则这些人从1到N编号。随后N行,第i行给出编号为i的人发红包的记录,格式如下:K N1 P1⋯NK PKK \ N_1\ P_1\cdots N_K\ P_KK N1 P1原创 2020-10-12 18:49:15 · 2232 阅读 · 0 评论 -
牛客小白月赛2 I.艺
牛客小白月赛2 I.艺题目链接题目描述接下去,Sεlιнα 又搞了个文艺竞演。虽说是文艺竞演,其实只是为了满足 Sεlιнα 的内心企盼——看群男友献歌献舞。她排列好了各个参赛男友的节目顺序,然后将他们安排在两个舞台上表演,自己则在演播室里使用两台闭路电视同时观看。万万没想到的是,当一切准备就绪时,其中一台电视炸了,她不会修,也没有时间修。于是只能尴尬地使用一台闭路电视观看两个舞台上的节目。当然,这台电视不支持分屏同时观看,所以 Sεlιнα 只能不停地换台观看。现在,作为导演的 Sεlιнα 已经原创 2020-08-14 16:57:47 · 2322 阅读 · 0 评论 -
LeetCode 290 单词规律
LeetCode 290 单词规律题目链接给定一种规律 pattern 和一个字符串 str ,判断 str 是否遵循相同的规律。这里的 遵循 指完全匹配,例如, pattern 里的每个字母和字符串 str 中的每个非空单词之间存在着双向连接的对应规律。示例1:输入: pattern = "abba", str = "dog cat cat dog"输出: true示例 2:输入:pattern = "abba", str = "dog cat cat fish"输出: false原创 2020-12-19 15:09:04 · 4981 阅读 · 2 评论 -
PAT甲级 1032 Sharing
PAT甲级 1032 Sharing题目链接To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix. For example, loading and being are stored as原创 2020-10-15 20:34:53 · 2285 阅读 · 0 评论 -
LeetCode 141 环形链表
LeetCode 141 环形链表题目链接给定一个链表,判断链表中是否有环。如果链表中有某个节点,可以通过连续跟踪 next 指针再次到达,则链表中存在环。 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 pos 是 -1,则在该链表中没有环。注意:pos 不作为参数进行传递,仅仅是为了标识链表的实际情况。如果链表中存在环,则返回 true 。 否则,返回 false 。思路: 直接遍历链表即可,如果有结点出现第二次就证明就有环,AC代码如原创 2020-10-09 12:16:37 · 2444 阅读 · 0 评论 -
LeetCode 75 颜色分类
LeetCode 75 颜色分类题目链接给定一个包含红色、白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。此题中,我们使用整数 0、 1 和 2 分别表示红色、白色和蓝色。注意:不能使用代码库中的排序函数来解决这道题。示例:输入: [2,0,2,1,1,0]输出: [0,0,1,1,2,2]简单计数题,直接用 mapmapmap 标记即可,AC代码如下:class Solution {public: void s原创 2020-10-07 10:08:14 · 3575 阅读 · 0 评论 -
LeetCode 501 二叉搜索树中的众数
LeetCode 501 二叉搜索树中的众数题目链接给定一个有相同值的二叉搜索树(BST),找出 BST 中的所有众数(出现频率最高的元素)。假定 BST 有如下定义:结点左子树中所含结点的值小于等于当前结点的值结点右子树中所含结点的值大于等于当前结点的值左子树和右子树都是二叉搜索树例如:给定 BST [1,null,2,2], 1 \ 2 / 2返回[2].简单BFS,统计每个结点出现的次数即可,AC代码如下:/** * Definition原创 2020-09-24 14:38:13 · 2438 阅读 · 0 评论 -
Educational Codeforces Round 93 (Rated for Div. 2) C. Good Subarrays
Educational Codeforces Round 93 (Rated for Div. 2) C. Good Subarrays题目链接You are given an array a1,a2,…,an consisting of integers from 0 to 9. A subarray al,al+1,al+2,…,ar−1,ar is good if the sum of elements of this subarray is equal to the length of this原创 2020-09-11 21:31:46 · 2434 阅读 · 2 评论 -
AtCoder Beginner Contest 176 E.Bomber
AtCoder Beginner Contest 176 E.Bomber题目链接比较简单的思维题,很明显,每一个点对行和列都有贡献值,我们只需找到最大的行贡献值和最大的列贡献值即可,这样成功了一大半,我们会发现行与列的交叉点如果有元素那么答案要减 111,那么我们可以记录所有等于最大贡献值的行号和所有最大贡献值的列号,判断是否存在交叉点即可 (很容易发现复杂度是 O(n)O(n)O(n) 的,而非 O(n2)O(n^2)O(n2)).这题惊人的 130 个点,还好一发过了????,AC代码如下:#原创 2020-08-23 09:03:10 · 2416 阅读 · 0 评论 -
Codeforces Round #662 (Div. 2) B. Applejack and Storages
Codeforces Round #662 (Div. 2) B. Applejack and Storages题目链接This year in Equestria was a year of plenty, so Applejack has decided to build some new apple storages. According to the advice of the farm designers, she chose to build two storages with non-ze原创 2020-08-08 10:38:38 · 2553 阅读 · 0 评论 -
2020牛客暑期多校训练营(第六场)K.K-Bag
2020牛客暑期多校训练营(第六场)K.K-Bag题目链接题目描述A sequence is called kk-bag, if and only if it is put in order by some (maybe one) permutations of 11 to kk. For example, 1,2,3,2,1,3,3,2,1 is a valid 3-bag sequence.Roundgod is not satisfied with kk-bag, so she put for原创 2020-07-30 16:41:11 · 2357 阅读 · 0 评论 -
HDUOJ 6794 Tokitsukaze and Multiple
HDUOJ 6794 Tokitsukaze and Multiple题目链接Problem DescriptionTokitsukaze 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 operation, a new element that equals to the sum of原创 2020-07-29 10:27:36 · 2591 阅读 · 0 评论 -
The Preliminary Contest for ICPC Asia Xuzhou 2019 B.so easy
The Preliminary Contest for ICPC Asia Xuzhou 2019 B.so easy题目链接There are n points in an array with index from 1 to n, and there are two operations to those points.1: x marking the point x is not available2: x query for the index of the first available原创 2020-06-26 19:18:43 · 2251 阅读 · 0 评论 -
2019牛客暑期多校训练营(第三场)J.LRU management
2019牛客暑期多校训练营(第三场)J.LRU management题目描述ZYB has finished his computer course recently. He is very interested in the LRU algorithm for cache management.To simplify the problem, assume that a block contains a name (which is a string) and a set of data (whic原创 2020-06-22 14:58:49 · 2337 阅读 · 0 评论 -
Codeforces Round #648 (Div. 2) C. Rotation Matching
Codeforces Round #648 (Div. 2) C. Rotation Matching题目链接After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation原创 2020-06-11 15:18:27 · 2401 阅读 · 0 评论 -
2020 年 “游族杯” 全国高校程序设计网络挑战赛 F.Find / -type f -or -type d
2020 年 “游族杯” 全国高校程序设计网络挑战赛 F.Find / -type f -or -type d题目链接这题其实不难,我们要判断每个字符串是否是其他串的子串即可,对每个字符串,标记它目录下的所有子串即可,最后遍历一遍,如果这个字符串只出现一次且后缀为 .eoj.eoj.eoj 则答案加1,AC代码如下:#include<bits/stdc++.h>using namespace std;typedef long long ll;string s[100005];mai原创 2020-05-23 19:50:29 · 2468 阅读 · 0 评论 -
AtCoder Beginner Contest 168 E.∙ (Bullet)
AtCoder Beginner Contest 168 E.∙ (Bullet)题目链接明显的数论题,我们假设知道某一对 Ai,BiA_i,B_iAi,Bi 的数量 numnumnum,那么他们可组成的符合条件的对数怎么算?首先在 numnumnum 里面至少要选一对,即从 Cnum1+Cnum2+⋯+Cnumnum=2num−1C_{num}^1+C_{num}^2+\cdots+C_{num}^{num}=2^{num}-1Cnum1+Cnum2+⋯+Cnumnum=2num−1,剩原创 2020-05-19 10:40:33 · 2478 阅读 · 0 评论 -
Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) B.Journey Planning
Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) B.Journey PlanningTanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad ...原创 2020-03-02 08:23:42 · 2539 阅读 · 2 评论 -
CTU Open Contest 2019 J.Beer Vision
CTU Open Contest 2019 J.Beer VisionWe are given a (drunken) image of stars as seen by a drunken man lying on his back on thegrass in the vicinity of a closed pub late in the evening. His image is a b...原创 2020-02-26 17:23:12 · 3102 阅读 · 0 评论 -
牛客小白月赛22 A.操作序列
牛客小白月赛22 A.操作序列题目描述给出一个长度无限的数列,初始全部为零,有三种操作:增加操作:给下标为 tt 的数加 cc 。特别注意,如果在下标 [t−30,t+30][t-30,t+30][t−30,t+30]内有不为零的数,增加操作无效。削减操作:让数列中下标最小的不为零数变为零。查询操作:查询数列中下标为 t 的数字是多少。输入描述:第一行包含一个整数 N,1≤N≤106...原创 2020-02-23 15:07:07 · 2773 阅读 · 1 评论 -
Codeforces Round #617 (Div. 3) C.Yet Another Walking Robot
Codeforces Round #617 (Div. 3) C.Yet Another Walking RobotThere is a robot on a coordinate plane. Initially, the robot is located at the point (0,0). Its path is described as a string s of length n c...原创 2020-02-06 10:29:17 · 2708 阅读 · 0 评论 -
HHUOJ 1062 死亡笔记
HHUOJ 死亡笔记题目描述Kajitsu发现了一个神秘的笔记本,上面记录写着n个名字。Kajitsu想知道,每个人的名字出现了几次。注意:本题输入不给定n,请自行判断输入末尾。输入输入仅一行,为n个名字,用空格隔开(n≤100,人名长度≤10)输出一共n行按照字典序顺序从小到大,每行为人名与对应出现次数,用空格隔开(字典序:先按照第一个字母、以 a、b、c……z 的顺序排列...原创 2019-11-20 23:53:27 · 2675 阅读 · 0 评论 -
Codeforces Round #590 (Div. 3) B2. Social Network (hard version)
B2. Social Network (hard version)The only difference between easy and hard versions are constraints on n and k.You are messaging in one of the popular social networks via your smartphone. Your smart...原创 2019-10-02 10:32:17 · 3081 阅读 · 5 评论 -
HHUOJ 1796 魔咒词典
HHUOJ 1796 魔咒词典题目描述哈利波特在魔法学校的必修课之一就是学习魔咒。据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮助。给你一部魔咒词典。当哈利听到一个魔咒时,你的程序必须告诉他那个魔咒的功能;当哈利需要某个功能但不知道该用什么魔咒时,你的程序要替他找到相应的魔咒。如果他要的魔咒不在词典中...原创 2019-06-07 08:20:00 · 788 阅读 · 0 评论 -
团体程序设计天梯赛 L2-034 口罩发放
团体程序设计天梯赛 L2-034 口罩发放题目链接为了抗击来势汹汹的 COVID19 新型冠状病毒,全国各地均启动了各项措施控制疫情发展,其中一个重要的环节是口罩的发放。某市出于给市民发放口罩的需要,推出了一款小程序让市民填写信息,方便工作的开展。小程序收集了各种信息,包括市民的姓名、身份证、身体情况、提交时间等,但因为数据量太大,需要根据一定规则进行筛选和处理,请你编写程序,按照给定规则输出口罩的寄送名单。输入格式:输入第一行是两个正整数 DDD 和 P(1≤D,P≤30)P(1≤D,P≤30)原创 2021-01-16 12:22:09 · 4517 阅读 · 1 评论 -
LeetCode 205 同构字符串
LeetCode 205 同构字符串题目链接给定两个字符串 s 和 t,判断它们是否是同构的。如果 s 中的字符可以按某种映射关系替换得到 t ,那么这两个字符串是同构的。每个出现的字符都应当映射到另一个字符,同时不改变字符的顺序。不同字符不能映射到同一个字符上,相同字符只能映射到同一个字符上,字符可以映射到自己本身。示例 1:输入:s = "egg", t = "add"输出:true示例 2:输入:s = "foo", t = "bar"输出:false示例 3:输入:s =原创 2020-12-29 15:47:49 · 3165 阅读 · 0 评论 -
LeetCode 143 Reorder List
LeetCode 143 Reorder List题目链接Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You may not modify the values in the list’s nodes, only nodes itself may be changed.Example 1:Given 1->2->3->4, reorder it to 1-原创 2020-10-20 09:04:37 · 2164 阅读 · 0 评论 -
LeetCode 1002 查找常用字符
LeetCode 1002 查找常用字符题目链接给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表。例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 3 次。你可以按任意顺序返回答案。示例 1:输入:["bella","label","roller"]输出:["e","l","l"]示例 2:输入:["cool","lock","cook"]输出:["c","o"]记录每个字符串的每个字符原创 2020-10-14 21:30:59 · 2288 阅读 · 0 评论 -
LeetCode 1 两数之和
LeetCode 1 两数之和题目链接给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。示例:给定 nums = [2, 7, 11, 15], target = 9因为 nums[0] + nums[1] = 2 + 7 = 9所以返回 [0, 1]暴力显然是可以的,但是肯定白给,所以得用 O(n)O(n)O(n) 的算法优化,我的思路如下:原创 2020-10-03 11:52:37 · 2531 阅读 · 0 评论 -
Codeforces Round #510 (Div. 2) D. Petya and Array
Codeforces Round #510 (Div. 2) D. Petya and Array题目链接Petya has an array a consisting of n integers. He has learned partial sums recently, and now he can calculate the sum of elements on any segment of the array really fast. The segment is a non-empty seq原创 2020-09-16 16:52:14 · 2397 阅读 · 0 评论 -
LeetCode 347 前 K 个高频元素
LeetCode 347 前 K 个高频元素题目链接给定一个非空的整数数组,返回其中出现频率前 k 高的元素。示例 1:输入:nums = [1,1,1,2,2,3], k = 2输出:[1,2]示例 2:输入:nums = [1], k = 1输出:[1]简单数据结构,AC代码如下:class Solution {public: vector<int> topKFrequent(vector<int>& nums, int k)原创 2020-09-13 18:32:17 · 2382 阅读 · 0 评论