自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 CF 1332B. Composite Coloring

A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren’t: 1, 2, 3, 17, 97.Alice is given a seq

2021-10-12 18:07:11 93

原创 CF 1438B. Valerii Against Everyone

You’re given an array b of length n. Let’s define another array a, also of length n, for which ai=2bi (1≤i≤n).Valerii says that every two non-intersecting subarrays of a have different sums of elements. You want to determine if he is wrong. More formally,

2021-10-02 15:33:53 111

原创 CF 1368B Codeforces Subsequences

Karl likes Codeforces and subsequences. He wants to find a string of lowercase English letters that contains at least k subsequences codeforces. Out of all possible strings, Karl wants to find a shortest one.Formally, a codeforces subsequence of a string

2021-10-02 14:17:48 185

原创 CF 1375C Element Extermination

You are given an array a of length n, which initially is a permutation of numbers from 1 to n. In one operation, you can choose an index i (1≤i<n) such that ai<ai+1, and remove either ai or ai+1 from the array (after the removal, the remaining parts

2021-09-29 23:19:26 94

原创 CF 1455B Jumps

You are standing on the OX-axis at point 0 and you want to move to an integer point x>0.You can make several jumps. Suppose you’re currently at point y (y may be negative) and jump for the k-th time. You can:either jump to the point y+kor jump to the

2021-09-26 16:43:39 93

原创 CF 1511B. GCD Length

You are given three integers a, b and c.Find two positive integers x and y (x>0, y>0) such that:the decimal representation of x without leading zeroes consists of a digits;the decimal representation of y without leading zeroes consists of b digits

2021-09-24 19:12:24 165

原创 CF 1381A1. Prefix Flip (Easy Version)

A1. Prefix Flip (Easy Version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the easy version of the problem. The difference between the versions is the constraint on n and the required num

2021-09-24 15:19:11 86

原创 CF1430A Number of Apartments

Recently a new building with a new layout was constructed in Monocarp’s hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It’s also known that each room of each apa

2021-09-21 14:26:38 64

原创 CF 1401C

You are given an array a1,a2,…,an where all ai are integers and greater than 0.In one operation, you can choose two different indices i and j (1≤i,j≤n). If gcd(ai,aj) is equal to the minimum element of the whole array a, you can swap ai and aj. gcd(x,y) d

2021-09-17 18:03:05 52

原创 CF 1474B Different Divisors

Positive integer x is called divisor of positive integer y, if y is divisible by x without remainder. For example, 1 is a divisor of 7 and 3 is not divisor of 8.We gave you an integer d and asked you to find the smallest positive integer a, such thata ha

2021-09-14 18:36:59 137

原创 CF 1348B Phoenix and Beauty

Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length k have the same sum. A subarray of an array is any sequence of consecutive elements.Phoenix currently has an array a of length n. He wants to insert some number of intege

2021-09-14 16:24:01 88

原创 CF 1370B GCD Compression

Ashish has an array a of consisting of 2n positive integers. He wants to compress a into an array b of size n−1. To do this, he first discards exactly 2 (any two) elements from a. He then performs the following operation until there are no elements left in

2021-09-12 14:40:27 86

原创 CF 766B Mahmoud and a Triangle

Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn’t accept challenges unless he is sure he can win, so he asked you to tell him if he should acce

2021-09-12 14:01:03 178

原创 CF 1365B Trouble Sort

B. Trouble SortThese elements are represented by two integers ai — the value of the element and bi — the type of the element (there are only two possible types: 0 and 1). He wants to sort the elements in non-decreasing values of ai.He can perform the fol

2021-09-12 13:01:40 73

原创 CF 1490B Balanced Remainders

You are given a number n (divisible by 3) and an array a[1…n]. In one move, you can increase any of the array elements by one. Formally, you choose the index i (1≤i≤n) and replace ai with ai+1. You can choose the same index i multiple times for different m

2021-09-12 12:09:24 117

原创 CF 1352C

You are given two positive integers n and k. Print the k-th positive integer that is not divisible by n.For example, if n=3, and k=7, then all numbers that are not divisible by 3 are: 1,2,4,5,7,8,10,11,13…. The 7-th number among them is 10.InputThe firs

2021-08-31 20:13:54 121

原创 博弈论 Nim

例题:给定 n 堆石子,两位玩家轮流操作,每次操作可以从任意一堆石子中拿走任意数量的石子(可以拿完,但不能不拿),最后无法进行操作的人视为失败。结论假设n堆石子,石子数目分别是 a1 , a2 , … , an,如果 a1 ⊕ a2 ⊕ … ⊕ an ≠ 0(Nim和),先手必胜;否则先手必败。证明1.终点情况:所有石子数量为零,该状态下属于失败,Nim 和为 a1 ⊕ a2 ⊕ … ⊕ an = 02.Nim和不为零:那么玩家必然可以通过拿走某一堆若干个石子将异或结果变为0。证明:设

2021-08-13 12:21:34 93

原创 数论

试除法判定质数每个合数都可以写成几个质数相乘的形式,这几个质数就都叫做这个合数的质因数。一个数合数c可以写成c = a * b(a<=b)。即判断n是否是质数只要将i从1枚举到sqrt(n),若i能整除n即n就为合数n = i * j(i<=j)。bool prime(int n){ if (x == 1) return false; for (int i = 2; i <= n / i; i++) { if (n % i == 0)

2021-08-10 14:33:21 232

原创 扩展中国剩余定理

对于每两个式子(我们考虑将其合并):{x≡a1(%m1)x≡a2(%m2)\left\{ \begin{array}{c} x≡a_1(\% m_1)\\ x≡a_2(\% m_2)\end{array}\right. {x≡a1​(%m1​)x≡a2​(%m2​)​则有:{x=a1+k1∗m1x=a2+k2∗m2\left\{ \begin{array}{c} x = a_1 + k_1 * m_1\\ x = a_2 + k_2 * m_2\end{ar

2021-08-09 16:44:53 58

原创 哈夫曼树

满足如下图的形式属于哈夫曼树。树的带权路径长度为:各个父结点与根节点之和,也就是除去叶子结点的和。实际等于:树的所有叶子结点从根节点到该叶子结点的路径长度与该叶子结点的权(结点数值)的乘积。WPL = 30 + 60 + 100 = 190WPL = (10 + 20) + (10 + 20 + 30) + (10 + 20 + 30 + 40) = 190WPL = 10 * 3 + 20 * 3 + 30 * 2 + 40

2021-07-28 12:35:41 78

原创 背包问题

背包问题什么是背包问题一、01背包问题二、完全背包问题什么是背包问题背包问题指这样一类问题,题意往往可以抽象成:给定一组物品,每种物品都有自己的重量和价格,在限定的总重量内,我们如何选择,才能使得物品的总价格最高。一、01背包问题1.问题描述: 有n件物品且每件物品只有一个和一个容量为V的背包。第i件物品的体积是v[i],价值是w[i]。求解将哪些物品装入背包可使这些物品的体积总和不超过背包容量,且价值总和最大。2.解题思路: dp问题首先解决:状态表示,状态集合,状态属性,集合划分。1.

2021-07-26 14:23:42 163

原创 容斥原理

有n个集合,求这n集合的并集。方法:容斥原理公式:S1 ⋃\bigcup⋃ S2 ⋃\bigcup⋃ S3 ⋃\bigcup⋃ … ⋃\bigcup⋃ Sn = Cn1C_{n}^{1}Cn1​ - Cn2C_{n}^{2}Cn2​ + Cn3C_{n}^{3}Cn3​ - Cn4C_{n}^{4}Cn4​ … (-1)(n-1) CnnC_{n}^{n}Cnn​共2n- 1项( 二项式定理 ( 1 + 1 )n - Cn0C_{n}^{0}Cn0​ 展开式 )例:有三个集合S1 = { 1

2021-07-14 22:01:35 403

原创 染色法判定二分图

二分图当且仅当图中不含有奇数环(由奇数条边形成的一个环),两个集合内部的内部没有边。算法思路一条边的两点染不同颜色,即证明这两点不属于一个集合(一个颜色代表一个集合)。当产生奇数环时,染色就会产生矛盾,即不存在二分图。dfs代码实现#include<iostream>#include<cstring>using namespace std;const int N = 2e5 + 10;int h[N], e[N], ne[N], idx;int

2021-07-06 13:08:37 98

原创 Kruskal算法求最小生成树

思路在原图中选择最小的边权,加其加入到生成树中,若此边在生成树中成环舍去。代码实现struct node { int a, b, w; bool operator<(node t) { return w < t.w; }} e[N];// 存边和权值int find(int x) // 并查集路径压缩查找{ if (p[x] != x) p[x] = find(p[x]); return p[x];}int kruskal(){ sort(e,

2021-07-05 16:50:32 77

原创 最小生成树Prim算法

MST性质理解设图的总结点为V,以落在生成树上的结点集为U,那么尚未落在生成树上的结点集为V - U。最小生成树最小边权选择:从U到V-U的连通边选择最短的边。prim算法思路选择:MST性质。加入:将选择的最短边的结点加入到生成树集中。更新:将加入的结点去更新他到尚未落在生成树上的结点集合。选择// dis为两个点的边权,vis判断该点是否在生成树集合中int t = -1;for (int j = 1; j <= n; j++){ if (!vis[j] &amp

2021-07-04 15:49:45 52

原创 bellman-ford

用处:1.解决存在负权边的最短路问题。2.解决有边数限制的最短路问题。(此算法特有)算法模板memset(dis, 0x3f, sizeof dis); dis[1] = 0;for (int i = 0; i < k; i++) // 遍历边数{ memcpy(backup, dis, sizeof dis); // 将上一条边的dis拷贝到backup for (int j = 0; j < m; j++) { int x = e[j].x, y = e[j].y,

2021-06-25 18:56:46 60

原创 Dijkstra求最短路

首先要明白这个算法的原理:如图:找v0到v6的最短路径。在找最短路之前先画一个表格:vj代表这一轮选出的最短路径,距离就是最短距离。无法到达用INF(无穷)表示具体寻找步骤:i=1:v1 = 13 , v2 = 8 , v3 = INF , v4 = 30 , v5 = INF , V6 = 32 这一轮选出的最短距离为v2 = 8。i=2: 既然v2是最短路那么从v2走到的点(可能更短)也被记录(每轮选出的最短路都可用)注意这里v2已被选出是最短路则不更新。v1 = 13 , v3

2021-06-20 14:33:05 132

原创 图的拓扑排序

拓扑排序就是对有向图结点排序,排序后的结果是没有一个节点指向它前面的节点。思路找入度为0的点,该点一定指向后面结点,将该点输出并删除该点所连的结点。循环此操作,直至所有结点全部输出。若输出的结点数小于图中的结点数,则表示该图存在回路(不存在度为0),即无法拓扑排序。拓扑排序不唯一。概括:只能从前往后走不能回头,度为0证明回不了头。代码实现#include<iostream>#include<cstring>using namespace std;co

2021-06-18 21:30:36 446

原创 哈希表及字符哈希

一、 定义哈希表是又称散列表,一种以 “key-value” 形式存储数据的数据结构(h[key] = value)。输入查找的值 key,就可以快速地找到其对应的 value。可以把哈希表理解为一种高级的数组,这种数组的下标可以是很大的整数,浮点数,字符串甚至结构体。但如果key值很大超出下标范围,这时就体现了哈希的作用,也就是key值的使用。二、key值的使用当 key 的范围比较小的时候,可以直接把 key 作为数组的下标。当 key 的范围比较大,比如以 10^9范围内的整数

2021-06-15 00:03:54 820 2

原创 并查集的应用

并查集并查集是一种树形的数据结构,顾名思义,它用于处理一些不交集的 合并 及 查询 问题。 它支持两种操作:查找(Find):确定某个元素处于哪个集合。合并(Union):将两个集合并成一个集合。查找思想:一棵树的根结点可以代表这棵树的所有元素,即查找过程,已知一棵树中的元素通过查找树的根结点,就可以确定这个元素属于哪棵树(集合)。用数组p[x]来存放x结点的根节点,即已知一个元素就可以访问其根结点,重复操作后即可访问这个元素所在的树的根节点。图解:补充:如果p[x]中的x为

2021-06-10 14:01:12 131

原创 Trie字符串统计数组实现

用数组来存取树方法实现:首先准备一个二维数组son[N][M] 和一个结点编号器idx。思想:1.son中的N表示根节点的编号,M表示孩子元素,整个son[N][M]表示根为N,孩子元素为M的孩子结点(实际就是通过根节点来访问孩子结点)。2idx的作用是给结点编号,使每一个结点独一无二(实际就是根节点,给根节点命个名来区分根节点)。例:输入三个字符串形成的数。a b ca bb d代码实现:void insert(){ int p = 0; for (int i = 0; c

2021-06-07 22:33:19 77

原创 表达式求值

思路:1.准备双栈,一个压入数字,另一个压入运算符。2.判断运算符优先级进行运算。(技巧:运算符栈按优先级形成单调递增)即当一个运算符入栈时,与栈顶元素比较。1)如果栈顶运算符优先级高,那么计算栈顶运算符所对应的式子,此时就完成了运算符优先级高的先运算。2)如果栈顶运算符优先级低,将当前运算符入栈。注意:运算规则是从左到右(后面会具体看解释)。实现代码:#include<iostream>#include<map>#include<stack>

2021-06-05 15:50:35 51

原创 双指针应用

双指针双指针就是两个指针(数组下标),共同维护一个区间或各维护一个区间。两指针维护区间模板:for (int i = 0, j = 0; i < n; i++) // 设置双指针维护区间 { while (j > n && check(i,j)) j++; //j不越界并且满足条件移动两指针各维护的区间存在一一对应模板:for (i = 0, j = 0; i < n; i++) // 双指针维护区间 { if( j<

2021-05-31 21:20:06 55

原创 离散化的应用

定义:当有些数据因为本身很大或者类型不支持,自身无法作为数组的下标来方便地处理,而影响最终结果的只有元素之间的相对大小关系时,我们可以将原来的数据按照从大到小编号来处理问题,即离散化。理解:区间范围很大(无法为数组下标)但能用的区间很离散,我们把这些离散的区间放在一起存起来,就是离散化过程。步骤:1.排序:(排序是为了查找(二分)一些需要用离散化的题目可能也需要排序)2.去重3.查找:(离散化就是用数组下标来表示原来的数据,通过二分查找来返回数据在数组中的下标)这里重点说一下去重的目

2021-05-29 23:21:54 167

原创 差分和前缀和

差分和前缀和前言什么是差分和前缀和一、前缀和的应用1.一维前缀和2.前缀和矩阵(二维)一、差分的应用1.一维差分2.差分矩阵(二维)前言什么是差分和前缀和有一个数组a,数组a中的元素为( a[1] , a[2] ,a[3] ... a[n]),数组下标从1开始a[0] = 0有一个数组b,数组b中的元素为(a[1] - a[0] , a[2] - a[1] , a[3] - a[2] ... a[n] - a[n-1])此时b是a的差分,a是b的前缀和总结:分差:就是该项与前一项的

2021-05-24 17:12:06 100

原创 SDUT OJ 2132 (一般算术表达式转换成后缀式)

题目描述Description对于一个基于二元运算符的算术表达式,转换为对应的后缀式,并输出之。Input输入一个算术表达式,以‘#’字符作为结束标志。Output输出该表达式转换所得到的后缀式。SampleInputa*b+(c-d/e)*f#Outputab*cde/-f*+转换规定从左到右遍历中缀表达式的每个符号和字母(数字),若是字母(数字)就输出,即成为后缀表达式的一部分;若是符号,则判断其与栈顶符号的优先级,是右括号或优先级低于栈顶符号(乘除优先加减)则栈顶

2021-05-21 19:57:15 106

原创 位运算及其应用

位运算前言二进制 -> 十进制十进制 -> 二进制一、原码,反码,补码1.负数的原码,反码,补码2.正数的原码,反码,补码二、位运算符1.按位 与 &2.按位 或 |3.按位 取反 ~4.按位 取异或 ^5.左移 <<6.右移 >>三、位运算的应用1.n的二进制表示第k位是几2.lowbit()函数总结前言学习位运算前要先了解二进制 -> 十进制,十进制 -> 二进制。二进制 -> 十进制例:-20 = 16 + 4这里解释一下

2021-05-16 15:24:32 346 2

空空如也

空空如也

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

TA关注的人

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