![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
省赛准备
小虎仔的csdn
欢迎来到算法的世界
展开
-
12203 Darker and Darker
每次可以把黑色方块的上下左右四个方向的白色方块变成黑色,问最少需要多少次才能把所有方块变成黑色#include<bits/stdc++.h>using namespace std;const int maxn=1e5+5;const int dx[]={1,-1,0,0};const int dy[]={0,0,1,-1};int n,m,ans;char s[1111...原创 2019-06-03 18:51:40 · 492 阅读 · 0 评论 -
Welcome Party(并查集加优先级队列)
RanklistZOJ Problem Set - 4109Welcome PartyTime Limit: 2 Seconds Memory Limit: 131072 KBThe 44th World Finals of the International Collegiate Programming Contest (ICPC 2020) will be held in M...原创 2019-04-29 13:49:15 · 480 阅读 · 2 评论 -
Coding Problem
Coding Problem如果没有三角形,那么数列是斐波拉契数列级别增长,所以个数<50;#include <iostream>#include <cmath>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#...原创 2019-04-20 10:44:12 · 153 阅读 · 0 评论 -
Little Sub and Triples
题目描述Little Sub has learned a new word ’Triple’, which usually means a group with three elements in it.Now he comes up with an interesting problem for you.DefineGiven an positive integer sequence A...原创 2019-05-04 21:06:04 · 278 阅读 · 0 评论 -
THE WORLD
题目描述The World can indicate world travel, particularly on a large scale. You mau be lucky enough to be embarking on a six-month overseas trip, or are working, studying or living overseas for an extend...原创 2019-05-04 20:00:14 · 182 阅读 · 0 评论 -
Distance
There are n points on a horizontal line, labelled with 1 through n from left to right.The distance between the i-th point and the (i+1)-th point is ai.For each integer k ranged from 1 to n, you are ...原创 2019-04-18 20:19:23 · 156 阅读 · 0 评论 -
用java实现逆矩阵运算
查java实现逆矩阵转换的代码,居然没怎么发现,想偷懒一下也不行。关于矩阵基本运算 :加 减 乘,转置矩阵,相当简单,能看见不少别人写的,但是就是没看见逆矩阵,不爽。自己实现了下逆矩阵功能,可以是任意的n阶矩阵。因为对矩阵很陌生,从0开始到最后实现,每一步的思考代码都有体现,所以代码就很有思考的逻辑性。实现分了两步:<最原始的公式>A的逆矩阵=A*/|A|;1:求A*...原创 2019-04-18 17:48:37 · 4868 阅读 · 3 评论 -
RMQ学习总结(附带简单例题)
RMQ (Range Minimum/Maximum Query)问题含义:对于长度为n的数列A,回答若干询问RMQ(A,i,j)(i,j<=n),返回数列A中下标在i,j里的最小(大)值,也就是说,RMQ问题是指求区间最值的问题。时间复杂度:预处理时间复杂度O(n*log(n)),查询O(1)基础:dpF[i][j]表示从第i位起,2^j个数中的最值。那么dp的初值是什么?显然...原创 2019-04-23 15:27:55 · 837 阅读 · 0 评论 -
字典树 数组模板
下面我们以HDU1521(统计前缀)为例传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1251指针代码:(C++提交可以通过,G++MLE,听大佬们说是G++在申请指针内存的同时也会申请一个指针对应类型大小的内存,这样消耗内存可能就是原来的两倍了#include<bits/stdc++.h>using namespace std;...原创 2019-04-27 11:21:58 · 288 阅读 · 0 评论 -
RMQ算法讲解
RMQ(Range Minimum/Maximum Query),即区间最值查询,这是一种在线算法,所谓在线算法,是指用户每次输入一个查询,便马上处理一个查询。RMQ算法一般用较长时间做预处理,时间复杂度为O(nlogn),然后可以在O(1)的时间内处理每次查询。下面我们从一个实际问题来解释RMQ我们假设数组arr为:1,3,6,7,4,2,5我们设二维数组dp[i][j]表示从第i位开始连...原创 2019-04-22 21:35:52 · 176 阅读 · 0 评论 -
Thanks, TuSimple!(加油!!!)
Thanks, TuSimple!#include <iostream>#include <cmath>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <string>#include &...原创 2019-04-15 13:25:48 · 296 阅读 · 0 评论 -
树状数组求逆序数
1、什么是逆序数? 在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序。一个排列中逆序数的总数就是这个排列的逆序数。2、用树状数组求逆序数的总数 2.1该背景下树状数组的含义 我们假设一个数组A[n],当A[n]=0时表示数字n在序列中没有出现过,A[n]=1表示数字n在序列中出现过。A对应的树状数组为c[n],则c...原创 2019-04-22 15:48:09 · 316 阅读 · 0 评论 -
P3368 【模板】差分树状数组
题目描述如题,已知一个数列,你需要进行下面两种操作:1.将某区间每一个数数加上x2.求出某一个数的和输入输出格式输入格式:第一行包含两个整数N、M,分别表示该数列数字的个数和操作的总个数。第二行包含N个用空格分隔的整数,其中第i个数字表示数列第i项的初始值。接下来M行每行包含2或4个整数,表示一个操作,具体如下:操作1: 格式:1 x y k 含义:将区间[x,y]内每个数加上k...原创 2019-04-22 12:52:09 · 114 阅读 · 0 评论 -
Potion
PotionTime Limit: 1 Second Memory Limit: 65536 KBBaoBao is brewing a magical potion. To brew this potion, types of ingredients, whose rank ranges from 1 to , is needed. More precisely, for all...原创 2019-04-14 19:46:02 · 450 阅读 · 0 评论 -
Little Sub and Enigma
题目描述Little Sub builds a naive Enigma machine of his own. It can only be used to encrypt/decrypt lower-case letters by giving each letter a unique corresponding lower-case letter. In order to ensure t...原创 2019-05-05 11:07:46 · 292 阅读 · 0 评论 -
分治算法(线段树分治)
先来一个按照中间值进行分治的例题:例题1 :最大连续和 C. 最大子段和NN个整数组成的序列 a[1],a[2],a[3],…,a[n],求该序列如 a[i]+a[i+1]+…+a[j]的连续子段和的最大值。当所给的整数均为负数时和为 0。...原创 2019-04-24 20:38:56 · 567 阅读 · 0 评论 -
A - Uint47 calculator(快速乘取模)
In the distant space, there is a technologically advanced planet.One day they provided the Earth with a code that could achieve the ultimate meaning of the universe. People were very happy, but found...原创 2019-04-24 21:33:11 · 348 阅读 · 0 评论 -
【BZOJ】有趣的家庭菜园
树状数组的getsum函数功能是判断左边比他小的个数,而i-1-getsum(x)是找右边比他小的,等于的话是i-getsum(x),惊人的发现,哈哈,排好序了吗,一开始是最大的,最后会形成一个序列,需要的步数就是最小的步数实现序列逆序对数,这个好像是一个结论,我也不是太懂,但是我觉得可以直接使用,也就是一个序列最小实现一个高峰序列的话,也就是求逆序对数最小可以形成的次数,注意相等的情况需要特判!...原创 2019-05-29 20:40:12 · 307 阅读 · 0 评论 -
B. 小花梨的三角形
B. 小花梨的三角形这个题目我真的是感触良多啊,怎么说呢,在一个上三角矩阵里面找出所有三角形的问题,正的三角形可以从第一个顶点开始遍历,设一个方程(i,j)(i+k,j),(i+k,j+k)来表示三角形的三个顶点,i表示共有几层,j表示每层有几个顶点,k表示从顶点向下走的距离,倒着的三角形可以这样表示,显然只有当第二层是才出现倒着的三角形,所以从第二层开始遍历,i表示几层,j表示一层有几个点,k...原创 2019-05-18 21:12:14 · 155 阅读 · 0 评论 -
问题 C: 线段交
线段交#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#define INF 0x3f3f3f3fusing namespace std;const int maxn = 105;st...原创 2019-05-21 21:28:58 · 22198 阅读 · 0 评论 -
问题 F: Black&White
题目描述你有一个长度为 n 的 01 串S,你可以执行最多 m 次操作。对于每次操作,你可以选择一个位置 i 满足 1≤i≤n,翻转这一位的值,0变成1,1变成0。定义一个 01 串的价值为其中最长连续0的个数和最长连续1的个数的较大值,求S在经过最多m次操作后的最大价值。输入第一行一个整数 T ,表示接下来有 T 个样例。首先输入n,m,表示S串的长度n和操作次数m,其中1≤n≤10...原创 2019-05-10 18:12:37 · 502 阅读 · 0 评论 -
melody
YellowStar is versatile. One day he writes a melody A = [A1, …, AN ], and he has a standard melody B = [B1, …, BN ]. YellowStar can split melody into several parts, it can be expressed as: K split pos...原创 2019-05-06 19:53:03 · 296 阅读 · 0 评论 -
Little Sub and Triangles
题目描述Little Sub loves triangles. Now he has a problem for you.Given n points on the two-dimensional plane, you have to answer many queries. Each query require you to calculate the number of triangles...原创 2019-05-06 10:56:18 · 105 阅读 · 0 评论 -
Increasing Subsequence (easy version)
Increasing Subsequence (easy version)#include <iostream>#include <iomanip>#include <algorithm>#include <stdlib.h>#include <cstdio>#include <cstring>#include ...原创 2019-04-30 15:09:18 · 279 阅读 · 0 评论 -
XOR Clique
XOR Clique这个题其实题意很简单,你可以找一下规律,其实这种题目你可以将1到30之间的数值给输出出来,找一下规律,这个题就是将2的j次方和2的j+1次方中数目最多的个数给输出出来。有个技巧就是将每个区间内的数字数目都存到a[j]中去,最后比较找最大值就好了#include <iostream>#include <cstdio>#include <alg...原创 2019-05-08 15:11:29 · 127 阅读 · 0 评论 -
Halting Problem
Halting Problem这个题目是模拟,256步操作,但超过256步时一定是死循环,否则按照题目模拟即可。学会strcmp的用法。#include <iostream>#include <cstdio>#include <algorithm>#include <stdlib.h>#include <cstring>us...原创 2019-05-08 14:31:52 · 136 阅读 · 0 评论 -
B. Long Number
B. Long Number#include <iostream>#include <iomanip>#include <algorithm>#include <stdlib.h>#include <cstdio>#include <cstring>#include <cmath>#include ...原创 2019-04-29 20:40:08 · 387 阅读 · 0 评论 -
Little Sub and Counting
题目描述Little Sub likes Math. Now he has a simple counting problem for you.Given an positive integer sequence A, for each Ai , Please calculate how many elements Aj in the sequence satisfi ed AiAj >...原创 2019-05-05 14:24:28 · 144 阅读 · 0 评论 -
A. Reachable Numbers
A. Reachable Numbers#include <iostream>#include <iomanip>#include <algorithm>#include <stdlib.h>#include <cstdio>#include <cstring>#include <cmath>#in...原创 2019-04-29 19:10:30 · 290 阅读 · 1 评论 -
Evolution Game(DAG)
题目描述In the fantasy world of ICPC there are magical beasts. As they grow, these beasts can change form, and every time they do they become more powerful. A beast cannot change form completely arbitrar...原创 2019-04-29 18:07:10 · 159 阅读 · 0 评论 -
树状数组入门(马马虎虎明白了)
简介树状数组这个东西。。。有人说它像线段树。。。其实感觉两者并没有什么直接联系。。。但是都是类似于树形操作的思想,所以经常把他俩放在一块说。。。稍微讲讲我对这个算法的见解,大家看看对不对。。。基本思想基本思想是这样的:首先来讲,树状数组较好的利用了二进制。它的每个节点的值代表的是自己和前面一些元素的和。至于到底是前面哪些元素,这就由这个节点的下标决定。比如下面这个图(图中的数字代表节...原创 2019-04-22 11:22:38 · 218 阅读 · 0 评论 -
问题 B: Slimming Plan
问题 B: Slimming Plan时间限制: 1 Sec 内存限制: 128 MB提交: 808 解决: 76[提交] [状态] [命题人:admin]题目描述Chokudai loves eating so much. However, his doctor Akensho told him that he was overweight, so he finally decid...原创 2019-04-14 12:52:48 · 145 阅读 · 0 评论 -
Just a Hook
成段更新(通常这对初学者来说是一道坎),需要用到延迟标记(或者说懒惰标记),简单来说 就是每次更新的时候不要更新到底,用延迟标记使得更新延迟到下次需要更新or询问到的 时候 o hdu1698 Just a Hook 题意:O(-1) 思路:O(-1) 线段树功能:update:成段替换 (由于只query 一次总区间,所以可以直接输出 1结点 的信息)线段树功能:update:成段替换 (由于...原创 2019-04-08 21:07:11 · 469 阅读 · 0 评论 -
逆序数 线段树
既然是区间操作 我们想到了线段树我们先建立一个空树 然后呢 按照这个序列的顺序将每个值插入 ,每次插入伴随一次查询 查询前面插入的比这次插入的大的数字的个数然后就可以了 复杂度 nlogn 可以接受需要注意 :1.很多时候可能要离散化 这个很容易想 因为如果数字是long long 类型以及以上的那么空间就爆了2.注意建立空树的时候要在 1-n+1上建立空树 因为有可能查询n query(...原创 2019-04-08 19:27:47 · 219 阅读 · 0 评论 -
问题 B: 黑暗意志
问题 B: 黑暗意志时间限制: 1 Sec 内存限制: 128 MB提交: 455 解决: 135[提交] [状态] [命题人:外部导入]题目描述在数千年前潘达利亚从卡利姆多分离之时,迷雾笼罩着这块新形成的大陆,使它不被外来者发现。迷雾同样遮蔽着这片大陆古老邪恶的要塞——雷神的雷电王座。在雷神统治时期,他的要塞就是雷电之王力量的保障。即使在他死后,强大而堕落的能量仍然在此萦绕不绝;而...原创 2019-04-02 23:14:03 · 265 阅读 · 0 评论 -
I Hate It
Problem Description很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。Input本题目包含多组测试,请处理到文件结束。在每个测试的第一行,有两个正整数 N 和 M ( 0<N<=200...原创 2019-04-08 17:01:14 · 154 阅读 · 0 评论 -
敌兵布阵
C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以...原创 2019-04-08 16:46:24 · 66 阅读 · 0 评论 -
线段树 例题排兵布阵
#include <iostream>#include <cmath>#include <algorithm>#include <cstdio>#include <cstring>#include <set>#include <queue>#include <stack>#define ...原创 2019-04-08 13:52:14 · 246 阅读 · 0 评论 -
线段树下推标记(懒惰标记,延迟标记)
解释:理论上来说,如果[3, 9]这个区间被修改的话,那么下图中的所有绿色的结点的值都要得到重新计算的:但是实际上是没有必要这么做的——我们可以引进一种叫做Lazy Tag,即延迟标记的东西——的确对于[3, 9]这样一次修改操作,我可以只去修改如下图中橙色的结点,但是在这个基础上,我要在[3, 9]分解出的4个区间[3, 3], [4, 5], [6, 8], [9, 9]所对应的结点上做...原创 2019-04-08 12:10:35 · 488 阅读 · 0 评论 -
线段树模板
综述线段树的原理:将[1,n]分解成若干特定的子区间(数量不超过4*n),然后,将每个区间[L,R]都分解为少量特定的子区间,通过对这些少量子区间的修改或者统计,来实现快速对[L,R]的修改或者统计。作用:对编号连续的一些点的区间信息进行修改或者统计操作主要操作:区间查询、点更新、区间更新时间复杂度:修改和统计的复杂度都是O(log(N))由原理可以看出线段树维护的信息必须满足区间加法...原创 2019-04-08 11:00:59 · 757 阅读 · 0 评论