首先抠出包围了阵形的最小矩形. 将地图拉伸成一条链,即将第一行.第二行.第三行按顺序连接.阵形也可以用同样的方法处理. 那么问题转化为,给定两个 01 串 S 和 T,问每个 S 中长度为 |T| 的子串是否存在 一个点,两个串对应字符都是 1. 将 T 串翻转,那么就变成了卷积的形式,FFT 计算即可. 在 BFS 求出所有可行的位置之后,对于答案的计算,也是卷积的形式,用 FFT 加速即可. 时间复杂度 O(nm log(nm))…
https://www.lydsy.com/JudgeOnline/problem.php?id=5217 Byteasar 组建了一支舰队!他们现在正在海洋上航行着.海洋可以抽象成一张n×m 的网格图,其中有些位置是“.”,表示这一格是海水,可以通过:有些位置是“#”,表示这一格是礁石,不可以通过:有些位置是“o”,表示这一格目前有一艘舰,且舰离开这一格之后,这一格将变为“.”.这些“o” 表示Byteasar 的舰队,他们每天可以往上下左右中的一个方向移动一格,但不能有任何一艘舰驶出地图.特…
Description Byteasar 组建了一支舰队!他们现在正在海洋上航行着.海洋可以抽象成一张n×m 的网格图,其中有些位置是" .",表示这一格是海水,可以通过:有些位置是"#",表示这一格是礁石,不可以通过:有些位置是"o",表 示这一格目前有一艘舰,且舰离开这一格之后,这一格将变为".".这些"o" 表示Byteasar 的舰队,他们每天 可以往上下左右中的一个方向移动一格,但不能有任何一艘舰…
被FFT的空间卡了半天 后来发现根本不用开那么大... 首先可以把包含舰艇的那个小矩形找出来 将它一行一行连接成一个串T 其中舰艇位置为1其他位置为0 将大矩形也连成串S 其中礁石为1其他为0 两个串匹配起来如果某一位两个串是1和1 则礁石与舰艇会在同一位置不可能到达 那么这个匹配所对应的图中的位置就不成立 因为要确定每个位置可以想到将T翻转后做FFT后每一位(每一位代表了一个小矩形的匹配情况)上结果是0就可以匹配上 为1不成立 选出为0的 做一遍BFS 求出可以到达的位置 可以发现可行的状态里…
2019-06-16 14:35:52 1089. Duplicate Zeros - Easy 问题描述: 问题求解: 很显然的可以使用O(n), O(n)的解法.主要问题在于如何在O(1)空间复杂度完成求解. 答案就是通过两次遍历,第一次求出复制后的数组的长度,第二次遍历填写数组. public void duplicateZeros(int[] arr) { if (arr.length == 1) return; final int n = arr.length; int newLen…
4.14 网络流专项测试 先看T1,不会,看T2,仙人掌???wtf??弃疗.看T3,貌似最可做了,然后开始刚,刚了30min无果,打了50分暴力,然后接着去看T1,把序列差分了一下,推了会式子,发现是傻逼费用流,然后码码码,码完秒过大样例,觉得比较稳,又肉眼查了会错,就放了.然后接着推T3,发现我会做一个限制条件的,貌似和T1差不多,然后就写了,感觉能多骗点分,之后看了看T2,发现30裸树剖,30裸最大流,然后码码码.最后查了会错,发现T1没开long long,赶紧改了.100+44+63=…
链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 题目描述 Eddy likes to play cards game since there are always lots of randomness in the game. For most of the cards game, the very first step in the game is shuffling the cards. And, mostly the randomn…
https://www.nowcoder.com/acm/contest/141#question 一眼背包,用四维dp记录在A,B,C,D条件限制下可以获得的最大知识点,但是题目要求输出路径,在输入中包含0这样的样例,原本的递归寻找路径变的不可行,就需要开五维dp记录在i组条件下ABCD的最大知识点,空间复杂度为36 ^ 5,测试可以通过,但本题有更加优秀的解法,就是在原本四维dp的条件下同时用状压记录已经选择的物品,输出的时候只要输出加入状压的物品即可. #include <map> #i…
链接:https://www.nowcoder.com/acm/contest/141/E 来源:牛客网 题目描述 Eddy likes to play with string which is a sequence of characters. One day, Eddy has played with a string S for a long time and wonders how could make it more enjoyable. Eddy comes up with foll…
链接:https://www.nowcoder.com/acm/contest/141/A 来源:牛客网 Eddy was a contestant participating , Eddy failed to solve a physics equation, which pushed him away from a potential medal. Since then on, Eddy found that physics is actually the most important th…
链接:https://www.nowcoder.com/acm/contest/141/E来源:牛客网 Eddy likes to play with string which is a sequence of characters. One day, Eddy has played with a string S for a long time and wonders how could make it more enjoyable. Eddy comes up with following…
链接:https://www.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy has solved lots of problem involving calculating the number of coprime pairs within some range. This problem can be solved with inclusion-exclusion method. Eddy has implemented it lots of times…
题目链接:https://www.nowcoder.com/acm/contest/141/C 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K Special Judge, 64bit IO Format: %lld 题目描述 Eddy likes to play cards game since there are always lots of randomness in the game. For most of the cards g…
题目链接:https://www.nowcoder.com/acm/contest/141/A 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K Special Judge, 64bit IO Format: %lld 题目描述 Eddy was a contestant participating in ACM ICPC contests. ACM is short for Algorithm, Coding, Math. Since in…
题目链接:https://www.nowcoder.com/acm/contest/141/H 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Eddy has solved lots of problem involving calculating the number of coprime pairs within some range. This problem can be so…
链接: https://www.nowcoder.com/acm/contest/141/C 题意: 给出一个n个元素的序列(1,2,...,n)和m个操作(1≤n,m≤1e5),每个操作给出两个数p和s(1≤pi≤n,1≤si≤n-pi+1),表示把序列中从p开始的s个数移到最前面,例如序列[1,2,3,4,5]在p=2,s=3时变成序列[2,3,4,1,5],输出最后的序列. 分析: 对于每个操作,直接把序列拆成三个部分,再重新拼接一下就行.可以用Splay或rope来快速完成这个操作. 代…
链接: https://www.nowcoder.com/acm/contest/141/A 题意: 有n(1≤n≤36)个物品,每个物品有四种代价pi,ai,ci,mi,价值为gi(0≤pi,ai,ci,mi,gi≤36),求四种代价分别不超过P,A,C,M(0≤P,A,C,M≤36)的条件下能获得的最大价值,输出所选择的物品. 分析: 01背包的思路,只是代价多了几个而已,数组开多几维就好了.可以用vis[i][p][a][c][m]来表示在四种代价分别为p,a,c,m的状态下是否用第i件物…
https://loj.ac/problem/6388 如果你做过BZOJ5217:[Lydsy2017省队十连测]航海舰队的话,那么恭喜你,这道题就是大水题. 如果你做过BZOJ4259:残缺的字符串的话,那么基本的字符串匹配FFT也是能想到的. 如果没做过的话,很抱歉,没有一定的套路的话这道题很难想(而对于我这样的蒟蒻来说就是没法想.) 将行走路线看做一个地图b,走过的路为1,没走的为0. 于是可以变成这张地图可以与原地图a匹配多少次(匹配成功在于两张图的1不能重叠.) 按照BZOJ5217…
题目链接(貌似未报名的不能进去):https://www.nowcoder.com/acm/contest/141/A 题目: 题意:背包题意,并打印路径. 思路:正常背包思路,不过五维的dp很容易爆内存,比赛时无限爆,后面队友提醒用short就过了.不过也可以用滚动减少内存消耗,两种代码实现都贴一下吧~ 五维代码实现如下: #include <set> #include <map> #include <queue> #include <stack> #in…
链接:https://www.nowcoder.com/acm/contest/141/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K Special Judge, 64bit IO Format: %lld 题目描述 Eddy was a contestant participating in ACM ICPC contests. ACM is short for Algorithm, Coding, Math. Sinc…
题目链接:https://www.nowcoder.com/acm/contest/141/C 题目描述 Eddy likes to play cards game since there are always lots of randomness in the game. For most of the cards game, the very first step in the game is shuffling the cards. And, mostly the randomness i…
Shuffle Cards 链接:https://www.nowcoder.com/acm/contest/141/C来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K Special Judge, 64bit IO Format: %lld 题目描述 Eddy likes to play cards game since there are always lots of randomness in the game. For m…
PACM Team 链接:https://www.nowcoder.com/acm/contest/141/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K Special Judge, 64bit IO Format: %lld 题目描述 Eddy was a contestant participating in ACM ICPC contests. ACM is short for Algorithm, Coding,…
链接:https://www.nowcoder.com/acm/contest/141/J 题目描述 Eddy has graduated from college. Currently, he is finding his future job and a place to live. Since Eddy is currently living in Tien-long country, he wants to choose a place inside Tien-long country…
链接:https://www.nowcoder.com/acm/contest/141/E 题目描述 Eddy likes to play with string which is a sequence of characters. One day, Eddy has played with a string S for a long time and wonders how could make it more enjoyable. Eddy comes up with following p…
链接:https://www.nowcoder.com/acm/contest/141/J来源:牛客网 Eddy has graduated from college. Currently, he is finding his future job and a place to live. Since Eddy is currently living in Tien-long country, he wants to choose a place inside Tien-long country…
链接:https://www.nowcoder.com/acm/contest/141/A来源:牛客网 Eddy was a contestant participating in ACM ICPC contests. ACM is short for Algorithm, Coding, Math. Since in the ACM contest, the most important knowledge is about algorithm, followed by coding(impl…
链接:https://www.nowcoder.com/acm/contest/141/E来源:牛客网 Eddy likes to play with string which is a sequence of characters. One day, Eddy has played with a string S for a long time and wonders how could make it more enjoyable. Eddy comes up with following…
链接:https://www.nowcoder.com/acm/contest/141/C来源:牛客网 Eddy likes to play cards game since there are always lots of randomness in the game. For most of the cards game, the very first step in the game is shuffling the cards. And, mostly the randomness in…
链接:https://www.nowcoder.com/acm/contest/141/A 来源:牛客网 题目描述 Eddy was a contestant participating in ACM ICPC contests. ACM is short for Algorithm, Coding, Math. Since in the ACM contest, the most important knowledge is about algorithm, followed by codin…