07 2020 档案
摘要:传送门 题意:给定一个n*m的地图,'.'空地,'#' 墙,'G'好人, 'B'坏人。问你存不存在一种方案,把若干空地变成'#'(人不能通过墙),使得所有好人能逃离地图,所有坏人不能逃离地图。(n,m)为出口,人存在的地方不能设置'#',保证出口一开始是空地。 思路: ① G == 0 Yes。 ②
阅读全文
摘要:传送门 题目: Polycarp wrote on the board a string s containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input.
阅读全文
摘要:传送门 题目:给定一个串“codeforces”,给定一个n,让你在原串上任意位置添加任意个数的字符构造出一个字符串s,使得至少有n组子序列能够组成“codeforces”,需要构造出的串长度最短,再输出构造出的s 思路:根据排列组合的性质,我们尽量平均“codeforces”上每位的个数即可。 1
阅读全文
摘要:传送门 题目: ①所有块之间能够相互到达,即使一个连通图 ②所有块有偶数个邻居 ③规定有n个块有4个邻居 每组测试给定一个n,问你怎么构造一个图。 思路:水题。我们先构造好一个边长为2的矩形,然后我们给该矩形右下角添加三个块就能表达一个“有四个邻居”的块。 1 #include <iostream>
阅读全文
摘要:传送门 题目:给定两个字符串A,B。我们可以改变A中任意数量相同的字符x变成字符y(必须满足y > x),我们能否把A变成B,可以的话最少几次,不可以输出‘-1’。 思路:看了所有样例后,再通过样例1可以想到一个方法。我们有一个矩阵app['a'~'t']['a'~'t']记录A与B的对应关系,例如
阅读全文
摘要:传送门 题目: Gottfried learned about binary number representation. He then came up with this task and presented it to you. You are given a collection of nn
阅读全文
摘要:题目: A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it! You are given integers n,k. Construct a grid AA with size n×n c
阅读全文
摘要:题目: Patrick likes to play baseball, but sometimes he will spend so many hours hitting home runs that his mind starts to get foggy! Patrick is sure tha
阅读全文
摘要:题目: Let a and b be two arrays of lengths n and m, respectively, with no elements in common. We can define a new array merge(a,b) of length n+m recursi
阅读全文
摘要:传送门 题目: There are two binary strings a and b of length nn (a binary string is a string consisting of symbols 0 and 1). In an operation, you select a p
阅读全文
摘要:传送门 题目:给定长度为n的数组,下标从0开始。你可以至多翻转一次连续的子数组,问a0 + a2 + ... + a2k最大是多少。 思路:我们发现一个情况: 20 30 10 ...,我们发现如果30和20反转也可以和后面10的的反转,就分成了两种情况,我们可以通过dp来解决,当前这个数与左边一起
阅读全文
摘要:传送门 题意:给定n本书,两个孩子A和B都至少需要读k本书,然后给定n本书的时间和两个孩子对这本书是否喜欢,问两个孩子都读了至少k本书的前提下最少的时间花费是多少?(如果这本书被选择,不论几个人读都是花费t的时间,不喜欢则说明不读) 思路:一开始想着像dp,但看了样例二发现是个简单的贪心,我们可以把
阅读全文
摘要:传送门 题目:可以改变'?'为任意'a'~'z'的字符,可不可以让s有且仅有一个子串为"abacaba"。 思路:暴力就行,枚举每个位置开始7个字符能否组成"abacaba",可以的话在判断此时把这7个位置的字符变成"abacaba"时,s有几个"abacaba"子串。 1 #include <io
阅读全文
摘要:传送门 题目:给定一个区间范围[l, r]和m,在区间[l, r]中取a, b, c,使得 na + b - c = m(n > 0)。 思路:na + b - c = m,可以看出a和n都是整数,则: na + b - c = m -> na = m - b + c b,c∈[l, r] -> n
阅读全文
摘要:传送门 题目:题目目标串有类似递归的要求。可以看出在左边界或者有边界存在连续的字符且是上个连续字符长度的一半,字符则是上个字符的下一个字符。 思路:容易想到二分,深度log(n),则复杂度O(n*log(n))。 我们可以直接分两种情况: ①左半边连续字符相同 ②右半边连续字符相同 我们把这个作为递
阅读全文
摘要:N children are playing Rochambeau (scissors-rock-cloth) game with you. One of them is the judge. The rest children are divided into three groups (it i
阅读全文
摘要:转载:https://www.cnblogs.com/xiongtao/p/11189452.html 题意:有一个n个点,m条边的图 ,给出每个点的度数,问是否可以成为该图的子图。 样例: n个点 m条边 每个点的度数 4 4 1 2 3 4 2 3 1 4 1 2 1 0 1 #include<
阅读全文
摘要:Minimum-cost Flow 题目:给n个点,m条边。接下来m行包含(a,b,c),即a,b之间有单位流量代价为c的边。接下来有q个问题,每个问题给定(x,y),即假设每条边的容量为x/y时,从点1到点n流1单位的流量,最少的花费是多少,如果无法从点1到点n流1单位的流量则输出“NaN”。 思
阅读全文
摘要:A Bug's Life Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different gend
阅读全文
摘要:Navigation Nightmare Farmer John's pastoral neighborhood has N farms (2 <= N <= 40,000), usually numbered/labeled 1..N. A series of M (1 <= M < 40,000
阅读全文
摘要:Parity game Now and then you play the following game with your friend. Your friend writes down a sequence consisting of zeroes and ones. You choose a
阅读全文
摘要:Supermarket A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as a
阅读全文
摘要:True Liars After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he wa
阅读全文
摘要:How Many Answers Are Wrong TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always wooing TT to play the fol
阅读全文
摘要:传送门 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <queue> 5 #include <vector> 6 #include <cmath> 7 8 using namespace std
阅读全文
摘要:0 or 1 题目: Given a n*n matrix C ij (1<=i,j<=n),We want to find a n*n matrix X ij (1<=i,j<=n),which is 0 or 1. Besides,X ij meets the following conditi
阅读全文
摘要:The Suspects 题目:编号为0的人有传染病,同组中只要有一个人有传染病,该组的人都被看做有传染病,一个人可以在多组中,问有多少人有传染病。 思路:并查集,需要压缩并查集的树,编号小的点优先作为祖先(0为root),并查集过程中传递祖先的同时传递祖先是否是病人,最后再次遍历所有人,使得祖先是
阅读全文
摘要:Wireless Network 思路:并查集,如果两个点可以相互传达,就是两个集合的合并,当然,前提是要两个点都被维修过。 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <queue> 5 #
阅读全文
摘要:Marriage Match IV 思路:属于最短路径上的边应该满足:dis_A[u] + dis_B[v] + w == dis_A[B],dis_A是出发点到其他点的距离,dis_B是终点到其他点的距离,u,v是边的两个端点,w是权值。题目说每条边只能用一次,我们可以用最大流算法来求最短路径有几
阅读全文