自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

转载 蓝桥杯 ALGO-1004 无聊的逗

试题 算法训练 无聊的逗问题描述  逗志芃在干了很多事情后终于闲下来了,然后就陷入了深深的无聊中。不过他想到了一个游戏来使他更无聊。他拿出n个木棍,然后选出其中一些粘成一根长的,然后再选一些粘成另一个长的,他想知道在两根一样长的情况下长度最长是多少。输入格式   第一行一个数n,表示n个棍子。第二行n个数,每个数表示一根棍子的长度。输出格式   一个数,最大的长度。 样例输入 4 1 2 3 1 样例输出 3 数据规模和约定   n<=15#include<bits/stdc++.

2022-01-01 15:43:11 641

转载 蓝桥杯 试题 算法训练 印章

试题 算法训练 印章动态规划:资源限制时间限制:1.0s 内存限制:256.0MB问题描述共有n种图案的印章,每种图案的出现概率相同。小A买了m张印章,求小A集齐n种印章的概率。输入格式一行两个正整数n和m输出格式一个实数P表示答案,保留4位小数。样例输入2 3样例输出0.7500数据规模和约定1≤n,m≤20题目意思简洁明了。。。。动态规划:1.设置状态(看是一维数组还是二维数组,一般的题目都是二维数组,经验之谈)2.找状态之间的关系,3.写代码这其中1,2是

2022-01-01 11:08:44 609 1

转载 字串排序(字符串)

【问题描述】小蓝最近学习了一些排序算法,其中冒泡排序让他印象深刻。在冒泡排序中,每次只能交换相邻的两个元素。小蓝发现,如果对一个字符串中的字符排序,只允许交换相邻的两个字符,则在所有可能的排序方案中,冒泡排序的总交换次数是最少的。例如,对于字符串 lan 排序,只需要 1 次交换。对于字符串 qiao 排序,总共需要 4 次交换。小蓝找到了很多字符串试图排序,他恰巧碰到一个字符串,需要 V 次交换,可是他忘了把这个字符串记下来,现在找不到了。请帮助小蓝找一个只包含小写英文字母且没有字母重复出现的字

2021-12-31 15:53:59 960

转载 平面切分(平面直线)

问题描述】平面上有 N 条直线,其中第 i 条直线是 y = Ai · x + Bi。【输入格式】第一行包含一个整数 N。以下 N 行,每行包含两个整数 Ai; Bi。【输出格式】一个整数代表答案。【样例输入】31 12 23 31234【样例输出】61【评测用例规模与约定】对于 50% 的评测用例, 1 ≤ N ≤ 4, −10 ≤ Ai; Bi ≤ 10。对于所有评测用例, 1 ≤ N ≤ 1000, −100000 ≤ Ai; Bi ≤ 100000。【

2021-12-31 15:30:52 700 1

转载 子串分值(字符串处理)

思路可以枚举,三重循环,这么算,n需小于100,显然不行每一个字母贡献的子串数,为其下标分别与前一个相同字母下标和后一个相同字母下标相减的绝对值相乘,再累计每一个字母即为答案比如图中这个字符串,记算4号位a的贡献子串数前一个a下标为1,后1个为6 (4-1)*(6-4)=6解释一下 4-1 对应着bca(234号) 6-4对应着ab(45号)分别以bca为起始位置,ba为终止位置的子串都只包含4号a,且是全部只包含4号a的子串即为bca bcab ca cab a ab注意初始,可能前..

2021-12-31 14:53:19 121

原创 最近公共祖先(LCA)

1172. 祖孙询问题目链接#include <algorithm>#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int N = 40010, M = N * 2;int n, m;int h[N], e[M], ne[M], idx;int depth[N], fa[N][16];int q[N];void add

2021-11-12 10:37:31 198

原创 树形dp系列

1072. 树的最长路径题目链接#include <algorithm>#include <cstring>#include <iostream>using namespace std;const int N = 10010, M = N * 2;int n;int h[N], e[M], w[M], ne[M], idx;int ans;void add(int a, int b, int c) { e[idx] = b, w[idx

2021-10-28 19:41:00 1600

原创 二分算法+

训练题目链接#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 2e5 + 10;const int INF = 0x3f3f3f3f;int n, m;int a[N], b[N], cnt[N];int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) {

2021-10-26 15:58:57 60

原创 无明显算法纯思维

3993. 石子游戏题目链接#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 2e5 + 10;const int INF = 0x3f3f3f3f;int n, m;int s[N];int minh = N, maxh = 0;int get(int j) { return s[maxh] - s[j - 1];}int main() { sc

2021-10-25 11:08:40 73

原创 双端队列广搜

175. 电路维修题目链接#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int, int> PII;const int N = 510;int n, m;char g[N][N];int d[N][N];int bfs() { memset(d, 0x3f, sizeof(d)); deque<PII> dq;

2021-09-13 11:13:41 58

原创 920. 最优乘车

920. 最优乘车题目链接#include <bits/stdc++.h>using namespace std;const int N = 510;int m, n;bool g[N][N];int dist[N];int stop[N];int q[N];void bfs() { int hh = 0, tt = 0; memset(dist, 0x3f, sizeof(dist)); q[0] = 1; dist[1] = 0;

2021-09-01 16:39:24 154

原创 3825. 逃离大森林

3825. 逃离大森林题目链接#include <bits/stdc++.h>#define x first#define y secondusing namespace std;typedef pair<int, int> PII;const int N = 1010;int n, m;char g[N][N];int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};int dist[N][N];int

2021-09-01 11:24:41 90

原创 最短路套题

1129. 热浪题目链接#include <bits/stdc++.h>using namespace std;const double eps = 1e-6;typedef long long ll;const int M = 1e6 + 10;#define maxn 3000#define maxn1 20000int n, m, start, ending, v, s, num;int dis[maxn], head[maxn]; // dis数组表示起点到某点的

2021-08-31 15:52:54 123

原创 3818. 餐厅

3818. 餐厅题目链接#include <bits/stdc++.h>using namespace std;typedef long long ll;const int M = 5 * 1e5 + 10;int n, a, b, ans;struct node { int l, r; node(int a, int b) { this->l = a, this->r = b; } bool operator<(const node

2021-08-30 16:30:14 81

原创 3816. 移动元素

3816. 移动元素题目链接#include <algorithm>#include <cstring>#include <iostream>#include <unordered_map>using namespace std;typedef long long LL;int n;LL a[100010];void solve() { cin >> n; unordered_map<LL, in

2021-08-30 15:07:23 74

原创 动态规划dp

美丽序列题目链接#include <string.h>#include <iostream>#define Mod 1000000007using namespace std;int main() { int n; long long a[42]; long long dp[42][42][3][1602]; // dp[i][j][1][k]代表当前 处理到第i个且值为j 在递减序列中第1个 前i个和为k memset(d

2021-08-25 20:57:27 66

原创 区间dp系列

牛牛的回文串题目链接#include <bits/stdc++.h>using namespace std;#define ll long long/* 解决一个回文串可以发现,添加一个字符和删除一个字符是等价的,删除一个字符相当于在另一侧添加一个字符,所以只需要计算删除一个字符 所需要的的代价即可,删除一个字符可以用过 1. 先将该字符change成另一个字符再删除 2. 添加任意一个字符再修改成该字符相当于添加 3. 将该字符替换成另一个字符c在通过添加另一个

2021-08-25 16:44:43 43

原创 线性dp系列

被3整除的子序列题目链接#include <bits/stdc++.h>using namespace std;typedef long long ll;const int M = 5 * 1e4 + 10;const int MOD = 1e9 + 7;string str;int dp[55][5];int main() { cin >> str; dp[1][(str[0] - '0') % 3] = 1; for (int i

2021-08-23 15:08:42 73

原创 莫队算法系列

数列互质题目链接#include <bits/stdc++.h>using namespace std;typedef long long ll;const int M = 5 * 1e4 + 10;const int MOD = 109;int n, m, unit, ans;int a[M], Be[M], sum[M];struct node { int l, r, k, id, ans;} e[M];set<int> s;bool cmp(

2021-08-22 17:51:23 67

原创 字符串哈希

圈圈题目链接#include <cstdio>#include <vector>using namespace std;typedef unsigned long long ull;const int maxn = 100005;int n, m, k, a[maxn];ull base = 100007, b[maxn], h[maxn];vector<int> v[maxn];int Solve(int s1, int s2, int add)

2021-08-20 16:39:25 90

原创 无效位置(牛客)

无效位置题目链接#include <bits/stdc++.h>using namespace std;//线性基模板typedef long long ll;struct Lbase{ ll p[64], q[64], tot; bool zero; Lbase() { memset(p, 0, sizeof(p)); tot = 0; zero = false; } //插入线性基(false插入失败) (true插入成

2021-08-04 23:17:04 95

转载 牛客Butterfly

Butterfly题目链接#include <stdio.h>#include <algorithm>using namespace std;const int maxn = 2005;char map[maxn][maxn];int len1[maxn][maxn], len2[maxn][maxn];int len3[maxn][maxn];int main() { int n, m; int i, j; char ch;

2021-08-04 19:59:24 84

原创 二分图匹配

A - 过山车题目链接#include <algorithm>#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <queue>#include <vector>using namespace std;const int N = 505;int line[N][N];int girl[N],

2021-08-03 16:20:51 82

转载 3785. 战舰

3785. 战舰#include <bits/stdc++.h>using namespace std;int main() { int n, k; cin >> n >> k; vector<vector<int>> a(n + 1, vector<int>(n + 1)); for(int i = 1; i <= n; i++) { for(int j = 1;

2021-07-31 09:52:29 51

转载 [CQOI2013]图的逆变换

[CQOI2013]图的逆变换题目链接#include <bits/stdc++.h>using namespace std;int T, n, m, e[305][305];bool check() { int f1 = 0, f2 = 0; for (int i = 1; i < n; ++i) for (int j = i + 1; j <= n; f1 = f2 = 0, ++j) for (int k

2021-07-30 21:12:04 67

原创 最优屏障(牛客)

最优屏障题目链接#include <algorithm>#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <queue>#include <stack>using namespace std;const int M = 5 * 1e5 + 10;int t, n;int a[M];int

2021-07-30 19:59:51 135

转载 博弈论专题

A - Good Luck in CET-4 Everybody!#include <iostream>#include <cstdio>using namespace std;typedef long long ll;int main(){ int n; while(cin>>n) { if(n%3==0) cout<<"Cici"<<endl; el

2021-07-30 10:30:31 78

转载 最小生成树

D - Qin Shi Huang’s National Road System#include <algorithm>#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <queue>#include <stack>using namespace std;const double eps =

2021-07-29 21:38:24 57

转载 3783. 第 k 个除数

3783. 第 k 个除数题目链接#include <bits/stdc++.h>using namespace std;typedef long long ll;int main() { ll n, k; cin >> n >> k; vector<ll> v; for (ll i = 1; i <= n / i; i++) { if (n % i == 0) {

2021-07-29 09:39:50 52

转载 2021牛客暑期多校训练营3

B-Black and white题目链接#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 3e7 + 10;const int M = 5010;struct node { int x, y; ll v; bool operator<(const node& u) const { return v < u.v; }}

2021-07-28 15:17:15 96

原创 树状数组套题

Contest题目链接#include <bits/stdc++.h>using namespace std;typedef long long ll;const ll N = 2e5 + 5;ll n, res, t[N];struct Node { ll a, b, c;} q[N];bool cmpa(Node x, Node y) { return x.a < y.a;}bool cmpb(Node x, Node y) { r

2021-07-28 09:40:59 254

转载 3782. 点

3782. 点题目链接#include <bits/stdc++.h>using namespace std;typedef long long ll;int n;ll ansx1, ansx2, ansy1, ansy2;int main() { cin >> n; for (int i = 0; i < n; ++i) { int x, y; scanf("%d%d", &x, &y);

2021-07-28 09:00:19 47

转载 线段树套题

A - 敌兵布阵题目链接#include <algorithm>#include <bitset>#include <cassert>#include <cctype>#include <cmath>#include <complex>#include <cstdio>#include <cstdlib>#include <cstring>#include <ctime

2021-07-25 15:56:59 56

原创 3777. 砖块

3777. 砖块题目链接#include <algorithm>#include <bitset>#include <cassert>#include <cctype>#include <cmath>#include <complex>#include <cstdio>#include <cstdlib>#include <cstring>#include <ctime

2021-07-24 20:37:51 70

原创 3775. 数组补全

3775. 数组补全题目链接#include <bits/stdc++.h>using namespace std;typedef long long ll;const int M = 200050;int t;int a[M];bool f[M];vector<int> v1, v2;int main() { cin >> t; while (t--) { memset(f, false, sizeof(f));

2021-07-24 09:43:08 97

转载 2021牛客暑期多校训练营2

J.Product of GCDs题目链接#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef double db;typedef pair<int, int> Pii;#define reg register#define mp make_pair#define pb push_back#define

2021-07-21 16:29:47 41

原创 3774. 亮灯时长

题目链接#include <bits/stdc++.h>using namespace std;typedef long long ll;const int M = 100050;int t;int a[M], b[M];int maxx;int main() { cin >> t; while (t--) { int n, m; cin >> n >> m; memset(a

2021-07-21 14:27:28 68

原创 3773. 兔子跳

#include <bits/stdc++.h>using namespace std;typedef long long ll;const int M = 100005;int a[M];int ans;int main() { int t; cin >> t; while (t--) { int n, x; cin >> n >> x; ans = 0; ...

2021-07-21 11:34:45 333

原创 3732. 矩阵复原

3732. 矩阵复原题目链接#include <algorithm>#include <bitset>#include <cassert>#include <cctype>#include <cmath>#include <complex>#include <cstdio>#include <cstdlib>#include <cstring>#include <cti

2021-07-01 10:57:17 80

原创 3711. 方格涂色

3711. 方格涂色题目链接#include <algorithm>#include <bitset>#include <cassert>#include <cctype>#include <cmath>#include <complex>#include <cstdio>#include <cstdlib>#include <cstring>#include <ct

2021-06-29 21:52:23 430

空空如也

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

TA关注的人

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