自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 暑假集训-Maximal submatrix

Problem DescriptionGiven a matrix of n rows and m columns,find the largest area submatrix which is non decreasing on each columnInputThe first line contains an integer T(1≤T≤10)representing the number of test cases.For each test case, the first line co

2021-07-21 08:50:30 162

原创 二分求最长上升子序列

大科学家dddd最近在研究转基因白菜,白菜的基因序列由一串大写英文字母构成,dddd经过严谨的推理证明发现,只有当白菜的基因序列呈按位非递减形式时,这株白菜的高附加值将达到最高,于是优秀的dddd开始着手修改白菜的基因序列,dddd每次修改基因序列的任意位需要的代价是11,dddd想知道,修改白菜的基因序列使其高附加值达到最高,所需要的最小代价的是多少。输入描述:第一行一个正整数n(1≤n≤1000000)第二行一个长度为n的字符串,表示所给白菜的基因序列保证给出字符串中有且仅有大写英文字母输出描

2021-05-29 20:09:11 142

原创 唯一分解定理

任何一个数都可已被分解为其质因数的平方例如:18=23的平方其因子个数为(1+1)(2+1)=6#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;typedef long long ll;const int maxn=1000005;long long f[maxn],k,prime[maxn];void su(){ memset(f,0,siz

2021-05-18 08:23:03 142

原创 扩展欧几里得模板

long long ex(long long a,long long b,long long &c,long long &d){ if(b==0) { c=1; d=0; return a; } long long k=ex(b,a%b,c,d); long long t=d; d=c-(a/b)*d; c=t; return k;}

2021-05-17 10:07:20 101

原创 欧拉函数模板

目前有两种筛选法求欧拉函数第一种:埃拉托斯特尼筛求欧拉函数时间复杂度为o(n*ln ln n)void shai(){ memset(prime,0,sizeof(prime)); prime[1]=1; for(int i=2;i<=maxn;i++) { if(prime[i]==0) { for(int j=i;j<=maxn;j+=i) {

2021-05-17 10:01:20 74

原创 spfa求最短路径

Alice and Bob are playing a game on a simple connected graph with N nodes and M edges.Alice colors each edge in the graph red or blue.A path is a sequence of edges where each pair of consecutive edges have a node in common. If the first edge in the pair

2021-05-05 08:44:02 100

原创 SPFA求次短路径

Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. She does not want to get to her old home too quickly, because she likes the scenery along the way. She has decided to take the second-shortest rather than the

2021-05-05 08:38:13 119

原创 最短路+二分

Huanhuan is always working on fansy programming questions. However, today he decided to give himself a break and travel to a beautiful country. Therefore, another problem arose.There are totally n cities in the country. There are m two-way roads, each of

2021-05-04 08:57:41 89

原创 逃离迷宫-广搜记录方向

给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位置,只能走到与它相邻的4个位置中,当然在行走过程中,gloria不能走到迷宫外面去。令人头痛的是,gloria是个没什么方向感的人,因此,她在行走过程中,不能转太多弯了,否则她会晕倒的。我们假定给定的两个位置都是空地,初始时,gloria所面向的方向未定,她可以选择4个方向的任何一个出发,而不算成一次转弯。gl

2021-04-30 19:45:20 130 1

原创 POJ - 1797—最短路

BackgroundHugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where

2021-04-29 21:41:41 121

原创 莫队

Given an array of N integers indexed from 1 to N, and q queries, each in the form i j, you have to find the number of distinct integers from index i to j (inclusive).InputInput starts with an integer T (≤ 5), denoting the number of test cases.The first

2021-04-20 21:49:58 79

原创 天梯赛—最小堆

7-11 关于堆的判断 (25 分)将一系列给定数字顺序插入一个初始为空的小顶堆H[]。随后判断一系列相关命题是否为真。命题分下列几种:x is the root:x是根结点;x and y are siblings:x和y是兄弟结点;x is the parent of y:x是y的父结点;x is a child of y:x是y的一个子结点。输入格式:每组测试第1行包含2个正整数N(≤ 1000)和M(≤ 20),分别是插入元素的个数、以及需要判断的命题数。下一行给出区间[−10000,

2021-04-20 21:10:43 75

原创 优先队列

公主被恶人抓走,被关押在牢房的某个地方。牢房用 N \times M (N, M \le 200)N×M(N,M≤200) 的矩阵来表示。矩阵中的每项可以代表道路(@)、墙壁(#)、和守卫(x)。英勇的骑士(r)决定孤身一人去拯救公主(a)。我们假设拯救成功的表示是 “骑士到达了公主所在的位置”。由于在通往公主所在位置的道路中可能遇到守卫,骑士一旦遇到守卫,必须杀死守卫才能继续前进。现假设骑士可以向上、下、左、右四个方向移动,每移动一个位置需要 11 个单位时间,杀死一个守卫需要花费额外的 11 个单位

2021-04-13 21:48:58 54

原创 快速幂+矩阵快速幂模板

快速幂long long q_pow(long long a,long long k,long long b)//求a^b%b{ long long f=1,s=a; while(k) { if(k&1) f=f*s%b; s=s*s%b; k=k/2; } return f;}矩阵快速幂#include<stdio.h>#include<string.h

2021-03-31 21:58:20 65

原创 判断二分图+二分图匹配

There are a group of students. Some of them may know each other, while others don’t. For example, A and B know each other, B and C know each other. But this may not imply that A and C know each other.Now you are given all pairs of students who know each o

2021-03-23 21:34:11 95

原创 字典树模板

Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let’s say the phone catalogue listed these numbers:Emergency 911Alice 97 625 999Bob 91 12 54 26In this case, it’s not possible to call Bo

2021-03-23 21:29:12 91

原创 凑算式--全排列

题目描述这个算式中A-I代表1~9的数字,不同的字母代表不同的数字。比如:6+8/3+952/714 就是一种解法,5+3/1+972/486 是另一种解法。这个算式一共有多少种解法?输出输出一个整数表示答案解析:因为A-I分别表示1-9不同的数字。所以我们可以将1-9进行全排列。如果满足上述算式就加一,最终可以求得有多少种情况。涉及知识点:全排列输入顺序从大到小:prev_permutation输入顺序从小到大:next_permutation#include<stdio

2021-03-22 20:02:20 282

原创 马走日--深度优先搜索

马在中国象棋以日字形规则移动。请编写一段程序,给定n*m大小的棋盘,以及马的初始位置(x,y),要求不能重复经过棋盘上的同一个点,计算马可以有多少途径遍历棋盘上的所有点。Input第一行为整数T(T < 10),表示测试数据组数。每一组测试数据包含一行,为四个整数,分别为棋盘的大小以及初始位置坐标n,m,x,y。(0<=x<=n-1,0<=y<=m-1, m < 10, n < 10)Output每组测试数据包含一行,为一个整数,表示马能遍历棋盘的途径总

2021-03-22 19:53:21 300

原创 拓扑排序

问题描述  小明的实验室有N台电脑,编号1~N。原本这N台电脑之间有N-1条数据链接相连,恰好构成一个树形网络。在树形网络上,任意两台电脑之间有唯一的路径相连。不过在最近一次维护网络时,管理员误操作使得某两台电脑之间增加了一条数据链接,于是网络中出现了环路。环路上的电脑由于两两之间不再是只有一条路径,使得这些电脑上的数据传输出现了BUG。为了恢复正常传输。小明需要找到所有在环路上的电脑,你能帮助他吗?输入格式第一行包含一个整数N。以下N行每行两个整数a和b,表示a和b之间有一条数据链接相连。对

2021-03-10 21:04:03 75

原创 最小表示法

Once upon a time there was a famous actress. As you may expect, she played mostly Antique Comedies most of all. All the people loved her. But she was not interested in the crowds. Her big hobby were beads of any kind. Many bead makers were working for her

2021-02-28 17:21:04 86

原创 ST算法

题目描述输入一串数字,给你 M个询问,每次询问就给你两个数字X,y ,要求你说出 X 到 Y这段区间内的最大数。输入格式第一行两个整数M,M 表示数字的个数和要询问的次数;接下来一行为N 个数;接下来 M 行,每行都有两个整数 X,Y。输出格式输出共 M行,每行输出一个数。样例输入10 23 2 4 5 6 8 1 2 9 71 43 8输出58这道题运用到了ST算法。什么是ST算法?ST算法:ST算法是用来解决区间最值得一种算法原理是倍增...

2021-02-28 16:21:28 251

原创 不一样的尼姆博弈

Alice and Bob are playing game of Misère Nim. Misère Nim is a game playing on k piles of stones, each pile containing one or more stones. The players alternate turns and in each turn a player can select one of the piles and can remove as many stones from t

2021-02-21 16:41:48 61

原创 扩展欧几里得

两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面的。为了帮助这两只乐观的青蛙,你被要求写一个程序来判断这两只青蛙是否能够碰面,会在什么时候碰面。我们把这两只青蛙分别叫做青蛙A和青蛙B,并且

2021-02-21 16:30:32 66

原创 二分

It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She is not afraid of this boring process. Jane has decided to use a radiator to make drying faster. But the radiator is small, so it can hold only one thing at

2021-02-04 15:32:34 99

原创 肥鼠吃奶酪——记忆化搜索

FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 <= p < n and 0 <= q < n. At each grid location Fatmouse has hid between 0 and 100 blocks of chee

2021-02-02 15:26:38 199

原创 博弈论——sg函数

任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1)=1;F(2)=2;F(n)=F(n-1)+F(n-2)(n>=3);所以,1,2,3,5,8,13……就是菲波那契数列。在HDOJ上有不少相关的题目,比如1005 Fibonacci again就是曾经的浙江省赛题。今天,又一个关于Fibonacci的题目出现了,它是一个小游戏,定义如下:1、 这是一个二人游戏;2、 一共有3堆石子,数量分别是m, n, p个;3、 两人

2021-01-30 13:43:29 202

原创 并查集删除

I hope you know the beautiful Union-Find structure. In this problem, you’re to implement somethingsimilar, but not identical.The data structure you need to write is also a collection of disjoint sets, supporting 3 operations:1 p q Union the sets contain

2021-01-30 12:38:59 118

原创 食物链——并查集

动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述:第一种说法是"1 X Y",表示X和Y是同类。第二种说法是"2 X Y",表示X吃Y。此人对N个动物,用上述两种说法,一句接一句地说出K句话,这K句话有的是真的,有的是假的。当一句话满足下列三条之一时,这句话就是假话,否则就是真话。1) 当前的话与前面的某些真

2021-01-24 15:26:17 106

原创 归并排序

In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input sequence9 1 0 5 4 ,Ul

2021-01-24 14:23:50 236

原创 最小生成树模板

最小生成树一般涉及两个算法:kruskal算法和prim算法废话不多说直接上模板kruskal算法#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn=100000;int f[maxn];int n,m;int tot=0,k=0;struct node{ int from,to,dis;}e[maxn];boo

2020-11-30 20:34:56 84

原创 AC自动机

在美丽的玄武湖畔,鸡鸣寺边,鸡笼山前,有一块富饶而秀美的土地,人们唤作进香河。相传一日,一缕紫气从天而至,只一瞬间便消失在了进香河中。老人们说,这是玄武神灵将天书藏匿在此。很多年后,人们终于在进香河地区发现了带有玄武密码的文字。更加神奇的是,这份带有玄武密码的文字,与玄武湖南岸台城的结构有微妙的关联。于是,漫长的破译工作开始了。经过分析,我们可以用东南西北四个方向来描述台城城砖的摆放,不妨用一个长度为 N 的序列来描述,序列中的元素分别是 E,S,W,N,代表了东南西北四向,我们称之为母串。而神秘的玄武

2020-11-22 09:10:47 118

原创 #10020. 「一本通 1.3 例 3」小木棍

乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过50 。现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开始时有多少根木棍和它们的长度。给出每段小木棍的长度,编程帮他找出原始木棍的最小可能长度。输入格式第一行为一个单独的整数 N表示砍过以后的小木棍的总数。 第二行为 N个用空格隔开的正整数,表示 N根小木棍的长度。输出格式输出仅一行,表示要求的原始木棍的最小可能长度。样例样例输入95 2 1 5 2 1 5 2 1样例输出6数据范围与提示1<=

2020-10-27 20:21:31 164

原创 线段树模板

第一步先建造树void build(int node,int L,int R){ if(L==R) tree[node]=a[L]; else { int mid=(L+R)/2; build(node*2,L,mid);//建立左子树 build(node*2+1,mid+1,R);//建立右子树 tree[node]=tree[node*2]+tree[node*2+1]; }}1.

2020-10-21 19:37:19 63

原创 记忆化搜索

这是一个简单的生存游戏,你控制一个机器人从一个棋盘的起始点(1,1)走到棋盘的终点(n,m)。游戏的规则描述如下:1.机器人一开始在棋盘的起始点并有起始点所标有的能量。2.机器人只能向右或者向下走,并且每走一步消耗一单位能量。3.机器人不能在原地停留。4.当机器人选择了一条可行路径后,当他走到这条路径的终点时,他将只有终点所标记的能量。如上图,机器人一开始在(1,1)点,并拥有4单位能量,蓝色方块表示他所能到达的点,如果他在这次路径选择中选择的终点是(2,4)点,当他到达(2,4)点时将拥有1

2020-10-19 21:22:16 80

原创 二叉树求先序和后序模板

给出一棵二叉树的中序与后序排列。求出它的先序排列。(约定树结点用不同的大写字母表示,长度≤8)。输入格式2行,均为大写字母组成的字符串,表示一棵二叉树的中序与后序排列。输出格式1行,表示一棵二叉树的先序。Sample InputBADCBDCASample OutputABCD#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char s

2020-10-16 15:15:10 198

原创 第十一届蓝桥杯:走方格

这道题其实很简单,刚开始想的是直接深搜。但是会超时,算是一道记忆化搜索的模板题#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int n,m,ans=0;int book[31][31];int s[2][2]= {{0,1},{1,0}};int dp[31][31];int dfs(int x,int y){ if(dp[x][y]>.

2020-10-14 20:53:30 498

原创 网络流:最大流EK算法

Mirko works on a pig farm that consists of M locked pig-houses and Mirko can’t unlock any pighouse because he doesn’t have the keys. Customers come to the farm one after another. Each of them has keys to some pig-houses and wants to buy a certain number of

2020-10-10 09:07:50 154

原创 数论

数论顾名思义就是数学的理论,就是用数学的理论去解题。如果找到其中的解题方法,代码一般很简短。要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。Input数据的第一行是一个T,表示有T组数据。每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。Output对应每组数据输出(A/B)%9973。Sample Input21000 5387 12345

2020-09-26 10:35:18 178

原创 最短路

最短路问题顾名思义,就是求一个点到另一个点的最短路径。先来介绍一种简单的算法,它只有5行,但是因为用了三层for循环,所以容易超时,但是处理较小数据还是一个挺不错的算法。首先将给出的路径初始化并赋值: for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if(i==j) e[i][j]=0; else e[i][j]=9999999; }

2020-09-26 10:01:17 81

原创 并查集+二分图

并查集是一种树型的数据结构,用于处理一些不相交集合的合并及查询问题。并查集由初始化,查找,合并三部分组成。初始化:void init(){ for(int i=0;i<=n;i++) f[i]=i;}查找:int getf(int v){ if(f[v]==v) return v; return f[v]=getf(f[v]);}合并:void merge(int x,int y){ int t1=getf(x

2020-09-26 09:33:52 488

空空如也

空空如也

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

TA关注的人

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