
思维题泛做
文章平均质量分 80
51nod、atcode、cf思维训练
_wjunjie
加油吧!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
百度之星 Diversity (简单树形dp)
题意描述:Diversity给你一棵n个点的树,对于节点ii,你要给它标上一个[li,ri]之间的数,要求所有边两端节点上标的数字的差的绝对值的总和最大。Input第一行一个整数T T(1≤T≤5)表示数据组数。对于每组数据格式如下。第一行一个正整数n(2≤n≤105)。接下来n-1行,每行两个正整数u, v(1≤u,v≤n),表示一条边。...原创 2019-09-01 11:18:44 · 228 阅读 · 0 评论 -
ACM-ICPC Nanjing 2018 现场赛 (巴什博弈变形)
题目描述:题意: 有N个石头,两人轮流取石头,每个人可以取标号连续的1~M个,没石头拿的人输掉比赛。问最后谁能赢。思路: 代码实现:#include <iostream>#include <string.h>#include <math.h>#include &l...原创 2019-08-19 20:05:20 · 255 阅读 · 0 评论 -
HDU 5876 Sparse Graph (求补图单源最短路O(N+M),N,M原图数据量)
Sparse GraphProblem DescriptionIn graph theory, thecomplementof a graphGis a graphHon the same vertices such that two distinct vertices ofHare adjacent if and only if they arenotadjac...原创 2019-08-17 16:53:29 · 294 阅读 · 0 评论 -
1043 幸运号码 (简单数位dp)
1043 幸运号码1个长度为2N的数,如果左边N个数的和 = 右边N个数的和,那么就是一个幸运号码。例如:99、1230、123312是幸运号码。给出一个N,求长度为2N的幸运号码的数量。由于数量很大,输出数量Mod 10^9 + 7的结果即可。输入输入N(1<= N <= 1000)输出输出幸运号码的数量 Mod 10^9 + 7输...原创 2019-08-15 19:22:53 · 298 阅读 · 0 评论 -
1040 最大公约数之和 ,GCD (X, Y) == Z 等价于 GCD (X/Z, Y/Z) == 1
1040 最大公约数之和给出一个n,求1-n这n个数,同n的最大公约数的和。比如:n = 61,2,3,4,5,6 同6的最大公约数分别为1,2,3,2,1,6,加在一起 = 15输入1个数N(N <= 10^9)输出公约数之和输入样例6输出样例15知识点:1、与n的公约数,肯定是n的因子2、那么我们枚举因子x就好了,显...原创 2019-08-15 16:19:38 · 636 阅读 · 0 评论 -
2621 树上距离 (倍增LCA 模板)
2621 树上距离有一棵n个节点的无向树,每条边有一个边权,现在有q次询问,每次询问给出两个点,求这两个点之间的简单路径上的边权和是多少。如图所示的数据中:1号节点和2号节点之间的距离为:22号节点和3号节点之间的距离为:2+2+3=7输入第1行:两个整数n和q,n表示这棵树的节点个数,q表示查询的次数。(1<=n,q<=1000)第2行~...原创 2019-08-13 16:38:28 · 487 阅读 · 0 评论 -
2620 序列问题 (序列合并问题——两两相邻)
2620 序列问题对于一个给定的序列a1,a2...ana1,a2...an,我们对它进行一个操作Reduce(i)Reduce(i),该操作将数列中的元素aiai和ai+1ai+1用一个元素max(aiai,ai+1ai+1)替代,这样得到一个比原来序列短的新序列。这一操作的代价是max(aiai,ai+1ai+1)。进行n-1次该操作后,可以得到一个长度为1的序列。我们的任务...原创 2019-08-13 15:19:06 · 1399 阅读 · 0 评论 -
2619 三个好朋友 (字符串Hash模板)
2619 三个好朋友有三个好朋友喜欢在一起玩游戏,A君写下一个字符串S,B君将字符串S复制一遍得到两个S拼接而成的字符串T,C君在T的任意位置(包括首尾)插入一个字符得到U.现在你得到了U,请你找出S。比如得到U串为ABABA。那么S串有可能是AB,T串为ABAB,之后在最后一个位置插入A,得到ABABA。S串还有可能是BA,T串为BABA,之后在第一个位置插入A,...原创 2019-08-13 11:46:22 · 956 阅读 · 0 评论 -
2617 小Biu过生日 (调和级数时间复杂度)
题目描述:2617 小Biu过生日今天是小Biu的生日,为了庆祝自己的生日,小Biu邀请n个朋友来玩一个游戏,小Biu给每个朋友一张带着数字的纸条,第i个朋友编号为i,纸条上的数字为aiai。小Biu让n个朋友坐成一个圈,除了1号与n号朋友外,i号朋友与i-1号朋友和i+1号朋友相邻,n号朋友与1号朋友相邻。之后每个朋友轮流走上一圈,第i个朋友拍打所有纸条上数字...原创 2019-08-12 22:24:07 · 483 阅读 · 0 评论 -
2615 修改01矩阵 (首行状态确定,整个状态即确定?)
2615 修改01矩阵有一个n*n的01矩阵,每次操作可以选择一个位置改变这个位置元素的值(0变成1,1变成0),但是这个位置的上下左右四个位置的元素的状态也会发生改变(0变成1,1变成0),问是否可以通过这个操作,将01矩阵所有元素都变成0,操作次数不限,也可以为0次。1 1 11 0 11 1 1在这个数据中,可以使所有元素都变成0的操作方式为:1 1 1...原创 2019-08-12 21:16:26 · 1162 阅读 · 0 评论 -
2610 粗心的小Biu (树上前缀和,略贪心)
题目描述:2610 粗心的小Biu小Biu有一棵n个节点的树,1号节点是这棵树的根,每个节点上有一个权值a。老师要求小Biu把每个节点计算一个新的权值b,权值b的大小为根节点到当前节点路径上的所有节点的权值。小Biu完成这个任务之后,由于太粗心,他不小心擦除了所有偶数层上节点的权值b。现在小Biu想知道,他如何安排每个被擦除的节点上的权值a,才能在满足让整棵树...原创 2019-08-12 16:20:54 · 742 阅读 · 0 评论 -
2609 最苗条的生成树(边权差值最小 生成树)
2609 最苗条的生成树定义一颗树的苗条度为这棵树的最大边权与最小边权的差值。现在有一个n个点m条边的无向联通图,求苗条度最小的生成树的苗条度是多少。如图所示的数据中:最优的选取方案选取的生成树的三条边分别为(1-4,4-2,1-3),所以答案为100-80=20。输入第1行:两个正整数n,m,n表示图中点的个数,m表示图中边的个数。(2<=n<=100...原创 2019-08-08 16:23:47 · 686 阅读 · 0 评论 -
2603 逃出城堡 (多源点bfs?/两次bfs)
2603 逃出城堡小Biu被困在一个城堡中,城堡可以看成一个大小为n*n的二维平面上的网格图,每一个格子要么为平地,要么为墙壁,要么为毒区,而且作为毒区的格子,每一秒会向他周围的上下左右四个格子扩散毒气(毒气不能穿过墙壁)。现在小Biu身负重任,最开始小Biu在某一个平地上,他每一秒可以向他上下左右四个格子中的作为平地的格子移动一步,他想知道如果不能穿越墙壁,也不能接触有毒...原创 2019-08-08 11:02:39 · 496 阅读 · 0 评论 -
2539 最优填充2 (相邻不同字母最少系列——求最优解方案数)
2539 最优填充2字符串ss只包含两种字符A,BA,B,已知它某些位上的字符,你想要把它填充完整使得相同字母相邻的情况尽量少,问有多少种最优填充方案。答案对1e9+7取模。输入第一行两个数n,m,表示字符串长度,已知位置数。第二行m个数pos[i];第三行一个长度为m的字符串val[i],表示s[pos[i]]=val[i]。保证pos[i]两两不同。n<=10...原创 2019-08-06 16:16:06 · 518 阅读 · 3 评论 -
2538 二三排列 (“2^n”种情况,“过程点不同,起始点一定一样”)
2538 二三排列给你nn个正整数,请你将其重排,使得后一个数是前一个数的三分之一(整除)或二倍。你只需判断是否有解,若有解,输出 ,否则输出 。,所有数字 。输入第一行一个数字 n 。第二行 n 个数字。输出一行一个字符串。若有解,输出 Possible,否则输出 Impossible 。输入样例33 1 2输出样例Possi...原创 2019-08-06 15:42:43 · 330 阅读 · 0 评论 -
AtCoder Regular Contest 080 ---C 4-adjacent(考虑不全面,bug)
题目描述: C - 4-adjacentProblem StatementWe have a sequence of lengthNN,a=(a1,a2,...,aN)a=(a1,a2,...,aN). Eachaiaiis a positive integer.Snuke's o...原创 2019-06-16 22:03:17 · 239 阅读 · 0 评论 -
AtCoder Regular Contest 081 D(模拟,乍一看dp、状压挺吓人)
题目描述:D - Coloring DominoesTime Limit: 2 sec / Memory Limit: 256 MBScore :400400pointsProblem StatementWe have a board with a2×N2×Ngrid. Snuke covered the board withNNdominoes witho...原创 2019-06-16 21:20:57 · 233 阅读 · 0 评论 -
AtCoder Regular Contest 079 D - Decrease (Contestant ver.)(构造题、读题要求高)
题目描述:Problem StatementWe have a sequence of lengthNNconsisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequenc...原创 2019-06-16 00:10:12 · 238 阅读 · 0 评论 -
AtCoder Regular Contest 078 D - Fennec VS. Snuke(树上小操作,统计子树节点个数,两点间路径保存)
题目描述:D - Fennec VS. SnukeTime Limit: 2 sec / Memory Limit: 256 MBScore :400400pointsProblem StatementFennec and Snuke are playing a board game.On the board, there areNNcells number...原创 2019-06-15 20:55:20 · 271 阅读 · 0 评论 -
AtCoder Regular Contest 077 D - 11(线性递推求逆元/费马小定理求逆元)
题目描述:D - 11Time Limit: 2 sec / Memory Limit: 256 MBScore :600600pointsProblem StatementYou are given an integer sequence of lengthn+1n+1,a1,a2,...,an+1a1,a2,...,an+1, which consists of ...原创 2019-06-13 00:15:38 · 262 阅读 · 0 评论 -
AtCoder Regular Contest 070 C - Go Home (构造序列)
题目描述:C - Go HomeProblem StatementThere is a kangaroo at coordinate00on an infinite number line that runs from left to right, at time00. During the period between timei−1i−1and time...原创 2019-06-01 09:08:46 · 265 阅读 · 0 评论 -
AtCoder Regular Contest 069 D - Menagerie(两个元素确定即可确定整个序列)
题目描述: D - MenagerieTime Limit: 2 sec / Memory Limit: 256 MBScore :500500pointsProblem StatementSnuke, who loves animals, built a zoo.There...原创 2019-05-31 17:36:56 · 372 阅读 · 0 评论 -
AtCoder Regular Contest 068 C - X: Yet Another Die Game(构造通解方案,状态不好,,)
题目描述:C - X: Yet Another Die GameTime Limit: 2 sec / Memory Limit: 256 MBScore :300300pointsProblem StatementSnuke has decided to play with a six-sided die. Each of its six sides show...原创 2019-05-31 00:53:22 · 238 阅读 · 0 评论 -
2018 焦作 现场赛(打表+数论积性函数)
题意:定义n种电阻,阻值{ inf| i%d2==0 && d>1 , i | else}。然后定义n种电阻集合,S[i]={ j | i%j==0} , 现在询问给定n找出一个集合Si,使得将Si内的电阻并联之后电阻值最小,输出最简分数格式。思路: 确定题意弄了半天,不是依次选择N个电阻,而是有N种选择集合,每种选择中固定有...原创 2019-08-22 22:24:43 · 180 阅读 · 0 评论 -
Codeforces Round #152 (Div. 2,B. Chilly Willy)(python大数练习)
B. Chilly WillyChilly Willy loves playing with numbers. He only knows prime numbers that aredigits yet. These numbers are2,3,5and7. But Willy grew rather bored of suchnumbers, so he came u...原创 2019-08-10 18:52:10 · 249 阅读 · 0 评论 -
2542 咖啡和作业 (简单二分)
Coffee and Coursework题意:泰泰学长必须写他的课程作业。他的课程作业包含m 页.为了提高效率,泰泰学长从某多多上买了n 杯咖啡. 对于第 i 杯咖啡泰泰学长可以摄取 ai 咖啡因. 泰泰学长打算喝一些咖啡来提高效率(每杯咖啡最多喝一次).他可以按照任何顺序喝咖啡. 泰泰学长喝每杯咖啡会马上喝完并且一滴不剩 (也就是说他不能把一杯咖啡分到两天喝)....原创 2019-08-07 22:28:21 · 305 阅读 · 0 评论 -
Codeforces Round #146 (Div. 2) D. Let's Play Osu!(经典概率dp)
D. Let's Play Osu!You're playing a game called Osu! Here's a simplified version of it. There arenclicks in agame. For each click there are two outcomes: correct or bad. Let us denote correct as...原创 2019-08-06 09:07:22 · 367 阅读 · 0 评论 -
Codeforces Round #148 (Div. 2) E. World Eater Brothers(思维+树形dp)
E. World Eater BrothersYou must have heard of the two brothers dreaming of ruling the world. With all theirprevious plans failed, this time they decided to cooperate with each other in order to...原创 2019-08-05 15:26:27 · 234 阅读 · 0 评论 -
Codeforces Round #149 (Div. 2) C. King's Path(坐标范围很大,数据量很小)
C. King's PathThe black king is standing on a chess field consisting of109rows and109columns.We will consider the rows of the field numbered with integers from1to109from topto bottom....原创 2019-08-04 16:02:00 · 223 阅读 · 0 评论 -
Codeforces Round #148 (Div. 2) D. Boring Partition(“证明?”唯一方案“取值最优?”)
D. Boring PartitionThis problem is the most boring one you've ever seen.Given a sequence of integersa1, a2, ..., anand a non-negative integerh, our goal isto partition the sequence into two ...原创 2019-08-03 17:16:07 · 277 阅读 · 0 评论 -
Codeforces Round #148 (Div. 2) C. Not Wool Sequences(前缀异或和)
C. Not Wool SequencesA sequence of non-negative integersa1, a2, ..., anof lengthnis called awool sequenceifand only if there exists two integerslandr(1 ≤ l ≤ r ≤ n)such that.In other...原创 2019-08-03 10:24:54 · 258 阅读 · 3 评论 -
Codeforces Round #145 F. TorCoder 26棵线段树维护字母变化?一颗就够了
F. TorCodertime limit per test3 secondsmemory limit per test256 megabytesinputinput.txtoutputoutput.txtA boy named Leo doesn't miss a single TorCoder contest round. On the last TorCoder round n...原创 2019-08-02 18:00:06 · 220 阅读 · 0 评论 -
Codeforces Round #145 (Div. 1 C. Practice) 递归求解,归并思想 / 巧妙二进制分解
C. PracticeLittle time is left before Berland annual football championship. Therefore the coachof team "Losewille Rangers" decided to resume the practice, that were indefinitelyinterrupted for ...原创 2019-08-01 15:39:58 · 222 阅读 · 0 评论 -
Codeforces 240E. Road Repairs 最小树形图+输出路径
题目大意:有N个城市,城市1是首都 ,有M条路,路的状态有两种,一种是可行的,另一种是不可行的,不可行的可以修成可行,但要花1单位的费用现在问,要让首都能到任意城市,需要花费的最小代价是多少,需要修的路是哪几条解题思路:最小树形图+输出路径(当成模板)题解代码:#include <iostream>#include <cstdio&...原创 2019-08-01 11:41:42 · 243 阅读 · 0 评论 -
Codeforces Round #145 (Div. 2 E. Champions' League) 使用 vector 简单模拟
E. Champions' LeagueIn the autumn of this year, two Russian teams came into the group stage of themost prestigious football club competition in the world — the UEFA ChampionsLeague. Now, these ...原创 2019-07-31 17:17:22 · 236 阅读 · 0 评论 -
Codeforces Round #145 (Div. 2 D Cinema)思维找切入点+简单模拟+一点容斥思想
D. CinemaOverall there aremactors in Berland. Each actor has a personal identifier — aninteger from1tom(distinct actors have distinct identifiers). Vasya ...原创 2019-07-31 15:06:55 · 146 阅读 · 0 评论 -
Codeforces Round #145 (Div. 2 F. Fence)简单三维DP
F. FenceVasya should paint a fence in front of his own cottage. The fence is a sequence ofnwooden boards arranged in a single row. Each board is a1centimeter wide rectangle. Let's numberthe...原创 2019-07-31 10:17:00 · 393 阅读 · 0 评论 -
Codeforces Round #140 (Div. 1) C. Anniversary(斐波那契数列的GCD性质+快速幂求斐波那契数列)
题意翻译 设 是斐波那契数列,在中选个数 ,使得尽可能大,输出对取模后的结果。样例输入输出:题解:from 洛谷 首先我们考虑斐波那契数列的一个性质: 然后只要找到最大的使得的倍数在里大于或者等于个即可.猜猜这个能不能二分...原创 2019-07-26 12:32:16 · 250 阅读 · 0 评论 -
Codeforces Round #138 (Div. 1) B. Two Strings(子序列染色,附判断子序列套路)
题目描述:题意: 用T串去匹配S串的任意子序列,如果匹配成功,将S种相应位置染色,可重复染色,若最后S串中所有位置均被染色,输出“Yes”,否则,输出“No”。思路: 按照判断子序列的思路匹配,如果Si和Tj匹配(Tj前面的均已被匹配),记录下j的位置,代表Si所能匹配到的最远距离,若不匹配,找Si前面最近的和Si字符相同的位...原创 2019-07-25 09:42:06 · 233 阅读 · 0 评论 -
补题
Problem A:异或数学题意:n个数中随机取1、2、3......n个数,求这些数的异或和。思路:异或类题目均转化为二进制求解。0^0=0,0^1=1,1^1=0,然后考虑换成二进制形式,这样异或的话价值只跟当前位置上1的个数有关系而且只有奇数个相同位置中的1相异或才能有结果因此我们只考虑每个位置上1的个数为0时候的贡献值如在第j位有num[j]个1,现在要从这n个数里面选i个数异...原创 2019-01-16 11:38:42 · 356 阅读 · 0 评论