自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(33)
  • 收藏
  • 关注

原创 线段树算法入门

什么是线段树线段树是一种二叉搜索树,借助分治算法思想,它将一个区间划分成一些单元区间,每个单元区间对应线段树中的一个叶结点。 -----------------改编自百度百科线段树的作用问题:给你nnn个无序数字,qqq次操作,询问某段区间[l,r][l, r][l,r]的和或是修改这段区间的值。假定1<=n,q<=100,0001 <= n, q <= 100,0001<=n,q<=100,000,给你的时间限制是1s1s1s。如

2021-08-03 07:18:43 126

原创 网络流算法入门

网络流常见算法网络流目前常见且实用的算法有4种:EK算法:时间复杂度为O(nm2)O(nm{^2})O(nm2),其中,nnn为顶点个数,mmm为边个数Dinic算法:时间复杂度为O(n2m)O(n{^2}m)O(n2m),其中,nnn为顶点个数,mmm为边个数ISAP算法:时间复杂度也为O(n2m)O(n{^2}m)O(n2m),其中,nnn为顶点个数,mmm为边个数HLPP算法:时间复杂度为O(n2m)O(n^2\sqrt{m})O(n2m​),其中,nnn为顶点个数,mmm为边个数网络

2021-07-29 07:06:58 470

原创 python正则学习

python 正则之前学过正则,久不用忘记了,没有笔记,现在重新学习一遍学习## search:只查询一次,直到出现第一个匹配## 匹配a或cimport reprint(re.search('[ac]','acd').group())## 输出: a## 匹配acimport reprint(re.search('ac','acd').group())## 输出: ac## 以a或c作为开头匹配import reprint(re.search('^[ac]','acd').

2021-04-18 22:15:43 181

原创 ACM模板

数论1.康托展开2.第一类斯特林数S(n,m)S(n,m)S(n,m)记为将nnn个元素划分为mmm个圆排列的方案数递推式:S(n,m)=S(n−1,m−1)+(n−1)∗S(n−1,m)S(n,m) = S(n-1,m-1) + (n - 1) * S(n-1,m)S(n,m)=S(n−1,m−1)+(n−1)∗S(n−1,m) $ ,$ n>mn > mn>m边界:S(n,0)=0S(n,0) = 0S(n,0)=0 S(n,n)=1S(n,n) =

2020-10-21 07:49:19 98 1

原创 Codeforces Round #624 (Div. 3) D (暴力,约束条件)

https://codeforces.com/contest/1311/problem/D

2020-08-13 01:52:48 94

原创 Codeforces Round #659 (Div. 1) A (并查集,拓扑排序,优先队列)

https://codeforces.com/problemset/problem/1383/A并查集 :https://blog.csdn.net/jziwjxjd/article/details/107603759拓扑排序 :https://blog.csdn.net/weixin_45817880/article/details/107573083优先队列 :#include<bits/stdc++.h>#define ios std::ios::sync_with_st

2020-08-12 11:19:27 117

原创 Educational Codeforces Round 76 (Rated for Div. 2) F (meet-in-the-middle)

https://codeforces.com/contest/1257/problem/F思路首先如果暴力做的话, 就是 100*2^30, 肯定 T。考虑 meet in the mid , 将 30 位的数拆分成前 15 位和后 15 位。然后暴力枚举 x 异或数组 a 的所有状态, 用 map 存起来, 然后考虑前 15 位和后 15 位组合起来能否满足要求。 (比如前 15 位中 a1 比 a2 多修改了一个 1, 那么在后 15 位中需要找到a2 比 a1 多修改一个 1 的进行组合)

2020-08-12 11:01:53 105

转载 POJ 3764 Language: The xor-longest Path (01字典树+DFS)

传送门:POJ 3764题目大意:在树上找一段路径(连续)使得边权相异或的结果最大。前置技能:用链式前向星建图。01字典树的应用。思路:本题用 vector数组建图是会超时的,所以只能用链式前向星建图了。由于是求异或的最值问题,可以考虑用 01字典树解决,又因为是在树上进行的,所以可以在 DFS遍历树的节点的同时把 当前节点到根节点相异或的结果 在01字典树中求异或的最大值并加到01字典树中去。你可能好奇,DFS过程中并没有取消点的访问,这样为什么就能保证你所求的结果对应的路径

2020-08-07 16:19:51 62

原创 dp训练

https://codeforces.com/problemset/problem/1373/D#include<bits/stdc++.h>#define ios std::ios::sync_with_stdio(false) , std::cin.tie(0) , std::cout.tie(0)#define rep(i,a,n) for (int i=a;i<=n;i++)#define per(i,n,a) for (int i=n;i>=a;i--)#defi

2020-08-06 09:52:31 125

原创 Codeforces Round #660 (Div. 2) D (拓扑排序,递归写法)

https://codeforces.com/contest/1388/problem/D思路使用拓扑排序,递归写的拓扑排序速度和空间开销较大,时间大约2倍,空间6倍多,有风险,但是代码简单,可以借鉴。故意卡数据的不存在。代码// 递归代码#include<bits/stdc++.h>#define ios std::ios::sync_with_stdio(false) , std::cin.tie(0) , std::cout.tie(0)#define rep(i,a,n)

2020-08-05 21:30:04 189

原创 Codeforces Round #660 (Div. 2) C(dfs)

https://codeforces.com/contest/1388/problem/C题意给定n个节点的树结构,m个人初始在根节点1号,已知每个人都有各自要到达的节点(默认走最短路),他们刚出发有各自的心情状态(好/坏)且我们未知,在节点之间的转移过程中好心情会转化为坏心情,但心情坏的不会发生改变。先给定每个节点数据h[i],理论上值为该节点上 心情好的人数 - 心情坏的人数,现要判断给定数据是否正确。思路设经过城市uuu的好心情人数为:g[u]g[u]g[u],拜访城市uuu的总人数为:a

2020-08-05 12:05:03 94

原创 Codeforces Round #656 (Div. 3) D (分治)

D. a-Good String题意定义一个字符串s为 c-好串(c为一个字符),必须满足:当|s|=1 ,s=c当|s|>1, s 的左半部分为全为 c,右半部分为一个 (c+1)-好串 或者 s 的右半部分为全为 c,左半部分为一个 (c+1)-好串题目给你一个字符串s,要求用最少的替换字符次数,使其变为一个 c-好串,求出最小值。思路暴力进行分治:当s长度大于等于2:ans1 = (s 的左半部分为全为c的代价 + 右半部分为一个 (c+1)-好串的代价)ans2

2020-08-04 16:32:23 77

原创 单调栈

Gym 102302A题意n个站台,每个站台i的高度为ai,求出每个站台能跳的最远距离。规则:只能跳过和这个站台一样高或者比这个站台还要低的站台,并且跳的最远距离为这个站台的高度,如果能跳出后面的所有站台,那么就停在第n个站台。思路使用单调栈,维护单调不递增。直接以样例例举:第一,二,三个站台依次进栈,当前5 2 2满足单调不递增,第四个站台要进栈时,第二第三个站台比第四个站台低,依次弹出栈,并且记录第二第三个站台的答案min(i+a[i],j-i-1),第四个站台入队。第五个站台入栈前,第四第一

2020-07-23 19:52:29 60

原创 Codeforces Round #642 (Div. 3) D(构造,优先队列)

https://codeforces.com/problemset/problem/1353/D题意给一个数n,构造出一个长度为n的序列a,这个序列的构造过程是这样的:序列a的各单位初始值均为0,它每次会挑选出最长的连续为0的区间,然后在这区间的中间标记第i次,i为目前操作次数,如果有多个长度相同的区间,优先选择左端点最小的那个区间,即最左边的区间。直到序列a没有0,构造结束,输出a思路每次选出的区间长度是最长的,其次是左区间最小的,这就可以考虑使用优先队列初始时将区间 [1,n] 存入优先队

2020-06-19 16:38:32 97

原创 Educational Codeforces Round 88 (Rated for Div. 2) C (数论,二分)

https://codeforces.com/problemset/problem/1359/C题意有无限的热水冷水,热水冷水轮流倒,先倒热水,再倒冷水,想要中和出的温度最接近温度t,请问最少倒多少杯水。思路先枚举找规律:第一杯温度为 h第二杯温度为 (h + c)/ 2第三杯温度为 (2*h + c)/ 3第四杯温度为 (2h + 2c)/ 4 =(h + c)/ 2第五杯温度为 (3h + 2c)/ 5可以看出偶数杯温度都为(h + c)/ 2奇数杯温度总是大于(h + c)

2020-06-19 13:20:15 95

原创 Codeforces Round #649 (Div. 2) C (思维)

链接题意已知长度为n的非递减数组a,构造出长度相同的数组 b,使得对于每个 i,b1, b2, … , bi 中未出现的最小非负整数为 ai 。思路得发现这个结论:当**a[i]!=a[i-1]**时 ,b[i] = a[i - 1]代码//过题代码#include<bits/stdc++.h>using namespace std;const int N = 1e6 + 10;int n,a[N],aa[N],ans[N],minn = 0;int main(

2020-06-15 10:12:50 107

原创 Codeforces Round #644 (Div. 3) F(暴力)

链接题目大意给n个串,让你写出一个字符串,满足与这n个串之间的差别在一个字符之内。思路n和m太小了,可以直接对这些串的每个字符进行由‘a’到‘z’的修改,然后存到map里面。复杂度大概为(26nmlog26m)代码#include<bits/stdc++.h>using namespace std;const int N = 1e2 + 10;int T,n,m;string s[N];map<string,int> mp;int main(){

2020-06-12 20:54:24 113

原创 Codeforces Testing Round #16 (Unrated)C (集合)

链接

2020-06-05 23:12:43 197

原创 Codeforces Round #645 (Div. 2) D(前缀和,二分查找)

链接题意

2020-06-05 23:11:10 124

原创 Codeforces Round #643 (Div. 2) C(数论,思维,前缀和)

链接题意给定四个数A B C D (A<=B<=C<=D<=5e5),创造三条边a (A<=a<=B),b(B<=b<=C),c(C<=c<=D),使这三条边可以组成一个三角形,求满足条件的总方案数。

2020-06-05 19:29:06 107

原创 Codeforces Round #529 (Div. 3) F(kul最小生成树)

链接题意给你n个互不相通的点,每个点有权值ai,题目要求将n个点连接生成最小生成树,连接两点的代价是这两个点的权值之和,但是,题目又给你m个特惠,每一个特惠都指定两个点一个特价:x,y,w,他们相连接不一定要以权值为代价,可以使用特价w代替,求代价最小值。思路使用kul建立最小生成树选出权值最小的点,e[++t]记录它与其他所有点,以及这两点连接的代价e[++t]记录特惠。针对数组e的w进行从小到大的快排fa[i] = i ( i 从1到n)for(i , 1 , t) (遍历e数

2020-05-27 20:54:07 114

原创 Codeforces Round #640 (Div. 4) F(思维,构造字符串序列)

链接F. Binary String Reconstructiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor some binary string s (i.e. each character si is either ‘0’ or ‘1’), all pairs of consecutive (adjacent) characte

2020-05-14 11:25:47 234

原创 Codeforces Round #640 (Div. 4) G (思维,构造数字序列)

链接G. Special Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA permutation of length n is an array p=[p1,p2,…,pn], which contains every integer from 1 to n (inclusive) and, moreover, ea

2020-05-14 10:28:52 131

原创 Codeforces Round #629 (Div. 3) D(思维)

链接D. Carouseltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe round carousel consists of n figures of animals. Figures are numbered from 1 to n in order of the carousel moving. Thus, after the

2020-05-11 20:22:34 80

原创 Codeforces Round #622 (Div. 2) B(思维)

链接B. Different Rulestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. Th

2020-05-11 20:18:38 98

原创 Codeforces Round #498 (Div. 3) F(异或,折半搜索)

链接F. Xor-Pathstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a rectangular grid of size n×m. Each cell has a number written on it; the number on the cell (i,j) is ai,j. Your task is to c

2020-05-11 14:38:19 142

原创 Codeforces Round #494 (Div. 3) D(2进制,贪心)

链接D. Coins and Queriestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has n coins, the value of the i-th coin is ai. It is guaranteed that all the values are integer powers of 2 (i.e. ai=

2020-05-11 12:56:22 123

原创 Codeforces Round #498 (Div. 3) D(字符串,模拟,分类讨论)

链接D. Two Strings Swapstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings a and b consisting of lowercase English letters, both of length n. The characters of both strings ha

2020-05-11 11:34:26 107

原创 Codeforces Round #506 (Div. 3) E(无向树,贪心)

链接E. Tree with Small Distancestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected tree consisting of n vertices. An undirected tree is a connected undirected graph with n−1

2020-05-11 10:54:45 99

原创 Codeforces Round #638 (Div. 2) C(思维,字符串,分类讨论)

C. Phoenix and Distributiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPhoenix has a string s consisting of lowercase Latin letters. He wants to distribute all the letters of his string into k

2020-05-10 10:33:43 126

原创 Codeforces Round #501 (Div. 3) D(贪心,模拟,思维)

链接D. Walking Between Housestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n houses in a row. They are numbered from 1 to n in order from left to right. Initially you are in the house 1.

2020-05-09 17:18:37 96

原创 Codeforces Round #629 (Div.3) B(思维,字符串,二分)

B. K-th Beautiful Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor the given integer n (n>2) let’s write down all the strings of l...

2020-03-30 22:51:06 263

原创 入门使用requests+xpath结合tkinter模块

功能:浏览侧边图片(红色框所示),tkinter模块代码如下:import tkinter as tkfrom lxml import etreeimport urllib.requestimport requestsfrom PIL import Image,ImageTkfrom tkinter import messageboxclass request: de...

2020-03-22 19:10:55 166

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除