I saw the same sub-problem in LeetCode, and there exists a O(n) neat greedy solution: for _ in range(int(input())): a = input() + '[' b = input() + '[' output = "" for _ in range(len(a) + len(b) - 2): if a < b: output += a[0] a = a[1:] else:…
Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the solution from this link:https://github.com/wangyongliang/Algorithm/blob/master/hackerrank/Strings/Square%20Subsequences/main.cc And here is his code with my…
Hackerrank 2020 February 2014 解题报告 比赛链接 Sherlock and Watson (20分) 题意:给定一个数组,向右平移K次,然后有Q个询问,问第x位置上是几 做法:直接模拟即可 #include <iostream> using namespace std; int n,k,q; ],b[]; int main(){ ios::sync_with_stdio(); cin>>n>>k>>q; ;i<n;i++)…
HackerRank - candies [贪心] Description Alice is a kindergarten teacher. She wants to give some candies to the children in her class. All the children sit in a line (their positions are fixed), and each of them has a rating score according to his or he…
https://www.hackerrank.com/challenges/reduced-string/problem He wants to reduce the string to its shortest length by doing a series of operations in which he selects a pair of adjacent lowercase letters that match, and then he deletes them. aaabccdd…
传送门:https://www.hackerrank.com/contests/world-codesprint-11/challenges/hackerland [题解] 因为加点每次加1个点1条边,所以不会存在一定要经过后加的那些点才能到达的情况. 直接把最后的图建出来,tarjan缩强联通分量+拓扑排序处理连通性. 拿个bitset维护拓扑排序过程即可.复杂度O(n^2/32) # include <queue> # include <bitset> # include &l…
题目链接:Running Time of Quicksort Challenge In practice, how much faster is Quicksort (in-place) than Insertion Sort? Compare the running time of the two algorithms by counting how many swaps or shifts each one takes to sort an array, and output the dif…
Problem Statement You are given a matrix with m rows and n columns of cells, each of which contains either 1or 0. Two cells are said to be connected if they are adjacent to each other horizontally, vertically, or diagonally. The connected and filled…
之前以为BinaryWriter写string会严格按构造时指定的编码(不指定则是无BOM的UTF8)写入string的二进制,如下面的代码: //将字符串"a"写入流,再拿到流的字节组data using (var ms = new MemoryStream()) { using (var bw = new BinaryWriter(ms)) { bw.Write("a"); } byte[] data = ms.ToArray(); } 因为字母a的utf8编码…