第十三届蓝桥杯C/C++ 大学B组题解

第十三届蓝桥杯C/C++ 大学B组

w l s wls wls的民间数据[Link](2022蓝桥杯省赛C++ B组(民间数据) - 课程 - Daimayuan Online Judge)

A 九进制转十进制

思路

模拟

答案 1478 1478 1478

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 1e5 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {
    e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int n, m, k;
int a[N];
int g(int n) {
    LL x = 1;
    while (n --) {
        x *= 9;
    }
    return x;
}
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout << 2 * g(3) + 2 * g(1) + 2 * g(0) << '\n';
    return 0;
}

B 顺子日期

思路

暴力枚举判断

答案: 0 , 1 , 2 0,1,2 0,1,2成立就是 14 14 14,不成立就是 4 4 4

不懂

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 1e5 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {
    e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int n, m, k;
int a[N];
int mo[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string str = "2022";

bool check(string str) {
    for (int i = 0; i + 2 < str.size(); i ++) {
        bool ok = true;
        for (int j = i + 1; j <= i + 2; j ++) {
            if ((int)(str[j - 1] - '0') + 1 != (int)(str[j] - '0')) 
                ok = false;
        }
        if (ok) return true;
    }
    return false;
}
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int res = 0;
    for (int i = 1; i <= 12; i ++) {
        string m = to_string(i), d;
        if (m.size() < 2) m = "0" + m;
        for (int j = 1; j <= mo[i]; j ++) {
            d = to_string(j);
            if (d.size() < 2) d = "0" + d;
            string t = str + m + d;
            if (check(t)) {
                res ++;                
            }
        }
    } 
    cout << res << '\n';
    return 0;
}

C 刷题统计

思路

循环节

a , b , n a,b,n a,b,n太大所以模拟行不通,七天一个循环节,所以 n = ( a × 5 + b × 2 ) × k + r n=(a\times 5+b\times 2)\times k + r n=(a×5+b×2)×k+r,所以看 n n n有几个循环节,最后再单独算一下 r r r的贡献即可。

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 1e5 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {
    e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
LL a, b, n;
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> a >> b >> n;
    LL d = (5 * a + 2 * b);
    LL res = n / d * 7;
    n %= d;
    for (int i = 1; i <= 7; i ++) {
        if (n <= 0) break;
        if (i < 6) n -= a;
        else n -= b;
        res ++;
    }
    cout << res;
    return 0;
}

D 修剪灌木

思路

贪心

​ 对于每一个位置,最优解应该是把它砍掉以后往左走或往右走再回来的最大值,因为如果有一个位置 t t t开始走到当前位置是最优解,我从当前位置到 t t t会多出一截,所以从当前位置走是最优的。

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 1e5 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {
    e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int a, b, n;
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i ++) {
        int d = max(i, n - i + 1);
        cout << d + max(0, d - 2);
        if (i != n) cout << '\n';
    }
    return 0;
}

E x进制

思路

贪心

这里有个很重要前提 A ≥ B A\ge B A≥B,假设第 i i i为的进制是 t i t_i ti​, p i = ( t 1 × t 2 × . . . × t i − 1 ) p_i=(t_1\times t_2\times ...\times t_{i-1}) pi​=(t1​×t2​×...×ti−1​),我们的答案就是 ∑ i = 1 n ( A i − B i ) × p i \sum_{i=1}^n (A_i-B_i)\times p_i ∑i=1n​(Ai​−Bi​)×pi​,由于我们题目保证 A ≥ B A\ge B A≥B,如果 A ≠ B A\ne B A​=B那么从高位到低位一定有某一位是 A i > B i A_i > B_i Ai​>Bi​的,进制合法所以不进位,因此高位具有决定性,所以我们只需要让所有位的进制都取最小合法的即可,即 m a x ( 2 , m i n ( A i , B i ) + 1 ) max(2,min(A_i,B_i) + 1) max(2,min(Ai​,Bi​)+1),单独每一位即可。

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 1e5 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {
    e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int n, m, k;
int la, lb;
LL a[N], b[N], c[N], p[N];
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    cin >> la;
    for (int i = 1; i <= la; i ++)
        cin >> c[i];
    for (int i = 1; i <= la; i ++)
        a[i] = c[la - i + 1];
    cin >> lb;
    for (int i = 1; i <= lb; i ++)
        cin >> c[i];
    for (int i = 1; i <= lb; i ++)
        b[i] = c[lb - i + 1];
    for (int i = 1; i <= max(la, lb); i ++) 
        p[i] = max(max(a[i], b[i]) + 1, 2ll);
  
    LL res = 0;
    LL pre = 1;
    for (int i = 1; i <= max(la, lb); i ++) {
        LL d = (a[i] - b[i]) * pre % mod;
        res = (res + d) % mod;
        pre = pre * p[i] % mod;
    }

    cout << (res % mod + mod) % mod;

    return 0;
}

F 统计子矩阵

思路

前缀和+双指针

​ 首先很容易想到枚举正方形的两个对角点,然后二维前缀和把查区间值降到 O ( 1 ) O(1) O(1),枚举复杂度为 O ( n 4 ) O(n^4) O(n4),骗点分。

​ 换一个方式来枚举,首先枚举上边和下边的位置,然后在这个子矩形里从左到右的算贡献,因为固定了上下边界,所以每一列相当于一个数(求和以后),就转化为在一个一维数组里有多少个连续的区间满足区间和 ≤ k \le k ≤k。

​ 计数类问题先划分,我们可以以区间右端点在那来划分这些区间,对于一个区间 [ l , r ] [l,r] [l,r](以 r r r为右端点成立的最长的区间)当右端点右移的时候区间和会变大,它的左端点不会从 1 1 1开始只会从上个区间 l l l往右移动,因此具有单调性我们可以双指针 O ( n ) O(n) O(n)的维护,对于一个成立的最大区间 [ l , r ] [l,r] [l,r]的贡献为 r − l + 1 r-l+1 r−l+1(从右端点往左扩有这些区间)。

​ 复杂度 O ( n 3 ) O(n^3) O(n3)

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 510, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {
    e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int n, m, k;
int s[N][N];
int main() {
    scanf("%d %d %d", &n, &m, &k);
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++) {
            scanf("%d", &s[i][j]);
            s[i][j] += s[i - 1][j];
        }

    LL res = 0;
    for (int l = 1; l <= n; l ++)
        for (int r = l; r <= n; r ++) {
            int sum = 0;
            for (int i = 1, j = 1; i <= m; i ++) {
                sum += s[r][i] - s[l - 1][i];
                while (sum > k) {
                   sum -= s[r][j] - s[l - 1][j];
                   j ++;
                }                               
                res += i - j + 1;
            }
        }
            
    printf("%lld\n", res);
    return 0;
}

G 积木画

思路

状压dp

考虑 f [ i ] [ j ] : 当 前 摆 到 第 i 列 且 占 了 i + 1 列 j 个 格 子 的 情 况 f[i][j]:当前摆到第i列且占了i+1列j个格子的情况 f[i][j]:当前摆到第i列且占了i+1列j个格子的情况

f [ i ] [ 0 ] = f [ i − 1 ] [ 0 ] + f [ i − 1 ] [ 2 ] f[i][0]=f[i-1][0]+f[i-1][2] f[i][0]=f[i−1][0]+f[i−1][2]

f [ i ] [ 1 ] = f [ i − 1 ] [ 0 ] × 2 + f [ i − 1 ] [ 1 ] f[i][1]=f[i-1][0]\times2+f[i-1][1] f[i][1]=f[i−1][0]×2+f[i−1][1]

f [ i ] [ 2 ] = f [ i − 1 ] [ 0 ] + f [ i − 1 ] [ 1 ] f[i][2]=f[i-1][0]+f[i-1][1] f[i][2]=f[i−1][0]+f[i−1][1]

为了不重复计算,初始我们让 f [ 1 ] [ 2 ] = 1 f[1][2]=1 f[1][2]=1表示上下摆放两个长条,并规定 f [ i ] [ 2 ] f[i][2] f[i][2]中由长条组成的情况只有上下摆放的情况,这里不算左右摆放长条是因为 f [ i ] [ 0 ] f[i][0] f[i][0]由 f [ i − 1 ] [ 0 ] , f [ i − 1 ] [ 2 ] f[i-1][0],f[i-1][2] f[i−1][0],f[i−1][2]转移过来从 f [ i − 1 ] [ 0 ] f[i-1][0] f[i−1][0]转移过了的情况存在最后并着两个长条的情况,因此不能再 f [ i − 1 ] [ 2 ] f[i-1][2] f[i−1][2]中计数。

由于只用前一维状态,可以滚动数组优化空间。

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 1e7 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1000000007;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {
    e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int n, m, k;
int a[N];
LL f[2][3];
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    f[1][0] = 1, f[1][1] = 2, f[1][2] = 1;
    for (int i = 2; i <= n; i ++) {
        f[i&1][0] = (f[i-1&1][0] + f[i-1&1][2]) % mod;
        f[i&1][1] = (f[i-1&1][0] * 2 + f[i-1&1][1]) % mod;
        f[i&1][2] = (f[i-1&1][0] + f[i-1&1][1]) % mod;
    }
    cout << f[n&1][0] << '\n';
    return 0;
}

线性dp

我的做法比较麻烦(不会状压dp的锅),考虑 f [ i ] [ j ] : 当 前 摆 到 第 i 列 且 往 第 i + 1 列 延 申 的 状 态 f[i][j]:当前摆到第i列且往第i+1列延申的状态 f[i][j]:当前摆到第i列且往第i+1列延申的状态

在这里插入图片描述

然后从前往后转移即可,一开始图省事开的 l o n g l o n g longlong longlong把空间炸了,寄,建议学滚动数组。

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 1e7 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1000000007;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {
    e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int n, m, k;
int a[N];
int f[N][4];
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    f[0][0] = 1;
    cin >> n;
    for (int i = 1; i <= n; i ++) {
       f[i][3] = ((LL)f[i - 1][0] + f[i][3]) % mod;
       f[i][0] = ((LL)f[i][0] + f[i - 1][0]) % mod;
       if (i >= 1)
          f[i][0] = ((LL)f[i][0] + f[i - 1][3]) % mod;
       f[i][1] = ((LL)f[i][1] + f[i - 1][0]) % mod;
       f[i][2] = ((LL)f[i][2] + f[i - 1][0]) % mod;
       f[i][1] = ((LL)f[i][1] + f[i - 1][2]) % mod;
       f[i][2] = ((LL)f[i][2] + f[i - 1][1]) % mod;
       f[i + 1][0] = ((LL)f[i + 1][0] + f[i - 1][1] + f[i - 1][2]) % mod;
      
    }   
   
    cout << (f[n][0] % mod + mod) % mod;
    return 0;
}

H 扫雷

思路

枚举,搜索

​ 比赛的时候读错题了,以为炮弹一发一发发射且求每一发最多炸多少, m d md md寄。

​ 暴力的想法我们可以把搞一个数组判断这个雷炸没炸,每个炮弹暴力的判断是否让一些雷炸掉然后再从这个没有炸过的雷向外 d f s dfs dfs算贡献即可,瓶颈在于枚举所有的雷上,观察发现 1 ≤ r ≤ 10 1\le r\le 10 1≤r≤10,因为我们只需要枚举当前雷的半径内是否存在雷即可,即判断范围内的点 x , y x,y x,y是否为某个雷的圆心即可。

​ 由于卡常,我们用 u n o r d e r e d _ m a p unordered\_map unordered_map来映射当前这个雷是否出现过,对于圆形相同的雷我们只需要记录它的最长半径和数量即可,然后暴力枚举范围内的点是否为雷是否可以继续往下搜即可。

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 5e4 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int n, m, k;
struct Node {
    int x, y, r, cnt;
}a[N];
bool st[N];
int idx, res;
unordered_map<LL, int> mp;
LL dist(int x1, int y1, int x2, int y2) {
    return (LL)(x1 - x2) * (x1 - x2) + (LL)(y1 - y2) * (y1 - y2);
}
LL calc(int x, int y) {
    return (LL)x * (1e9 + 1) + y;
}
void dfs(int u) {
    res += a[u].cnt;
    st[u] = true;
    for (int x = a[u].x - a[u].r; x <= a[u].x + a[u].r; x ++) {
        for (int y = a[u].y; dist(x, y, a[u].x, a[u].y) <= (LL)a[u].r * a[u].r; y ++) {            
            if (x >= 0 && x <= 1e9 && y <= 1e9) {
                if (mp.find(calc(x, y)) != mp.end()) {
                    int id = mp[calc(x, y)];
                    if (!st[id])    
                        dfs(id);
                }
            }
        }
        for (int y = a[u].y; dist(x, y, a[u].x, a[u].y) <= (LL)a[u].r * a[u].r; y --) {            
            if (x >= 0 && x <= 1e9 && y <= 1e9) {
                if (mp.find(calc(x, y)) != mp.end()) {
                    int id = mp[calc(x, y)];
                    if (!st[id])    
                        dfs(id);
                }
            }
        }
    }
}
int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i ++) {
        int x, y, r;
        scanf("%d %d %d", &x, &y, &r);        
        if (mp.find(calc(x, y)) == mp.end())
            mp[calc(x, y)] = ++idx, a[idx] = {x, y, r, 1};
        else {
            int id = mp[calc(x, y)];
            a[id].r = max(a[id].r, r);
            a[id].cnt ++;
        }
    }
    
    for (int i = 1; i <= m; i ++) {
        scanf("%d %d %d", &a[idx + 1].x, &a[idx + 1].y, &a[idx + 1].r);  
        dfs(idx + 1);        
    }

    printf("%d\n", res);
    return 0;
}

I 李白打酒加强版

思路

d p dp dp

​ 考场上没动脑子,直接上了个二进制枚举暴力骗了点分。

​ 由于 m ≤ 100 m\le 100 m≤100且 m m m每次只能减 1 1 1所以我们身上的酒不能超过当前的 m m m否则就喝不完了,考虑 f [ i ] [ j ] [ k ] : 当 前 路 过 i 个 店 , j 个 花 且 酒 还 剩 k 的 方 案 数 f[i][j][k]:当前路过i个店,j个花且酒还剩k的方案数 f[i][j][k]:当前路过i个店,j个花且酒还剩k的方案数。我们直接枚举方案数往后一个可以转移的状态转移即可,注意一下转移是否合法即可,不合法的情况有 1. 当 前 这 个 是 店 且 k × 2 > m    2. 当 前 这 个 是 花 且 k = = 0    3. 当 前 这 个 是 店 但 是 j = = m 1.当前这个是店且k\times 2>m\ \ 2.当前这个是花且k==0\ \ 3.当前这个是店但是j==m 1.当前这个是店且k×2>m  2.当前这个是花且k==0  3.当前这个是店但是j==m。

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 1e5 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {
    e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int n, m, k;
int a[N];
int f[110][110][101];
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> m;
    f[0][0][2] = 1;
    for (int i = 0; i <= n; i ++)
      for (int j = 0; j <= m; j ++) 
          for (int k = 0; k <= m; k ++) {
              if (k * 2 <= m && j != m) 
                  (f[i + 1][j][k * 2] += f[i][j][k]) %= mod;
              if (k)
                  (f[i][j + 1][k - 1] += f[i][j][k]) %= mod;
          }
    cout << f[n][m][0] << '\n';
      
    return 0;
}

J 砍竹子

思路

​ 贪心

​ 它的这个开根的操作最多 6 , 7 6,7 6,7次就会把一个数开到 1 1 1,贪心的来看我们一定是让一些一样的尽量高一起被砍更优。对于每个竹子单独砍会有从它到 1 1 1的一些过程值,无非是砍到和它前一个的公共最长前缀一样还是和它后一个的公共最长前缀一样然后再一起砍掉,这个时候我就很蠢的写了区间 d p dp dp骗了点分就 r u n run run了。

​ 继续往下贪心,对于当前位置:

​ 如果和左边公共前缀更长,那么它就会砍一些变成左边的这个前缀

​ 如果右边更长,我们其实是要变成右边的前缀然后然后再一起变成左边这个前缀,我们把这两步的贡献都计入当前砍成左边前缀

​ 因此每一个点看看砍成左边最长前缀需要几步就可以了,特殊的第一个点它的前面是 1 1 1。

​ 找前缀可以预处理然后暴力判断,我这里直接那个 m a p map map搞的,复杂度高一些,也可以接受。

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 2e5 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {
    e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int n, m, k;
LL g(LL x) {
    return sqrt(x / 2 + 1);
}
int dist(LL x, LL y) {
    map<LL, bool> mp;
    while (y > 1) {
        mp[y] = true;
        y = g(y);
    }    
    int res = 0;
    while (x > 1) {
        if (mp[x]) {
            break;
        }
        res ++;
        x = g(x);
    }
    return res;
}
LL res;
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    LL pre = 1, res = 0;    
    for (int i = 1; i <= n; i ++) {
        LL x; cin >> x;
        res += dist(x, pre);
        pre = x;
    }
    cout << res << '\n';
    return 0;
}

PPO实战:如何用强化学习让小车爬上MountainCarContinuous-v0山顶(附完整代码) 本文提供了使用PPO算法解决MountainCarContinuous-v0环境的完整实战教程。针对该环境的连续动作空间和稀疏奖励挑战,文章详细解析了PPO智能体的网络架构、状态归一化、GAE优势估计等核心实现,并附带了可直接运行的PyTorch代码。同时分享了关键的调参技巧和实战避坑指南,帮助读者高效训练智能体完成小车爬坡任务。 阅读详情

相关推荐

ROS2+PYTHON VENV虚拟环境配置方法

ROS2+PYTHON VENV配置方法本篇针对的是python。

下雨夏云的博客 555

背包问题(c++)

i++) printf("物品%d重%d公斤,价值%d元\n",g[i].No,g[i].w,g[i].v);printf("物品%d重%d公斤,价值%d元\n",g[i].No,g[i].w,g[i].v);printf("需要切割,切出重量为%d的物品%d装入背包\n",c,g[i].No);printf("递归能装入背包的最大价值为%f元\n",greedy_gui(g,c,0));printf("背包最大承重:%d公斤\n",c);

m0_69846376的博客 401

Unity3D实战:5分钟搞定RTSP监控视频流播放(附完整代码)

本文详细介绍了如何在Unity3D中快速实现低延迟RTSP监控视频流播放,提供完整代码和优化方案。通过Video Player组件和FFmpeg集成,开发者可以轻松应对智能家居和安防监控领域的实时视频流挑战,显著降低延迟并提升性能。

weixin_29015051的博客 587

背包问题c++

背包问题 在学习过程中碰到背包问题,有两种解法。(记录)

qq_51408826的博客 290

HDMI与DisplayPort混搭方案:如何用Xilinx Video PHY Controller实现多协议视频接口转换

本文详细解析了如何利用Xilinx Video PHY Controller IP核实现HDMI与DisplayPort协议转换,涵盖混合视频接口架构设计、GT收发器动态重配置策略及跨协议时钟域处理方案。通过实战案例和配置技巧,帮助开发者构建高性能多协议视频转换系统,适用于医疗影像、工业控制等场景。

weixin_30776273的博客 447

电子发票二维码背后的秘密:10分钟看懂校验码、加密字符含义与防伪设计

本文深入解析电子发票二维码的结构与防伪设计,揭示校验码和加密字符的生成原理及验证方法。通过实际案例和技术细节,帮助财务人员理解电子发票的安全机制,提升防伪识别能力,确保税务合规。

weixin_29248611的博客 530

第十三届蓝桥杯C++B组答案

第十三届蓝桥杯C++B组答案

qq_64358646的博客 3187

PCL Super4PCS算法实现点云粗配准(版本一)【2025最新版】

Win11系统下实现[Super4PCS: Fast Global Pointcloud Registration via Smart Indexing一文中的配准算法。

点云侠的博客 3378

第十三届蓝桥杯国赛C++B组(个人题解)

好难啊呜呜呜呜呜,填空题第一个就懵了真要命。这是个人题解(就是说不一定对,大家看个乐子就行,后续把题补了再改)在 12 小时制的钟表中,有分针、时针、秒针来表示时间。记分针和时针之间的夹角度数为 A(0 ≤ A ≤ 180)、分针和秒针之间的夹角度数为 B(0 ≤ B ≤ 180)。而恰好在 s 时 f 分 m 秒时,满足条件 A = 2B 且 0 ≤ s ≤ 6; 0 ≤ f < 60;0 ≤ m < 60,请问 s, f, m 分别是多少。注意时针、分针、秒针都围绕中心匀速转动。提交格式为三个由一个空格

fnmdpnmsl的博客 2255

SoulX-FlashHead 加速实践,提升3倍。

SoulX-FlashHead 加速实践,提升3倍。

jacke121的专栏 221

[AI] 嵌入模型选择:bge / text-embedding-3 / Jina Embeddings 对比与选型指南

摘要: 本文对比了BGE-M3、OpenAI和Jina三种主流嵌入模型在语言覆盖、性能、延迟、维度和成本等维度的差异。BGE-M3适合中文场景,本地部署成本低;OpenAI API多语能力强但依赖网络;Jina在多语表现突出但需关注商用许可。测试显示BGE-M3本地延迟3-6ms,OpenAI API延迟200-600ms。选型建议:隐私场景选BGE本地部署,多语低维护选OpenAI,高精度选Jina。部署时需注意批处理优化、向量库压缩和商用许可等问题,建议建立评测指标并监控关键指标。

每日出拳老爷子的博客 428

蓝桥杯第十三届C++B组真题

【代码】蓝桥杯第十三届C++B组真题。

lll123830的博客 573

Python实现多元线性回归(Multiple Linear Regression)

多元线性回归是一种用于建立多个自变量与因变量之间关系的统计学方法。在多元线性回归中,我们可以通过多个自变量来预测一个因变量的值。每个自变量对因变量的影响可以用回归系数来表示。

优快云 精品推荐 4331

2022第十三届蓝桥杯大赛软件赛省赛C/C++ 大学 B 组(题解&解析)

记录刷题的过程、感悟、题解。 希望能帮到,那些与我一同前行的,来自远方的朋友😉

2302_80067378的博客 1万+

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

第十三届蓝桥杯 C/C++ 大学B组 题解

进制计算简单模拟。

万伏小太阳 2958

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

2022 第十三届蓝桥杯大赛软件赛省赛,C/C++ 大学B组题解

2022 第十三届蓝桥杯大赛软件赛省赛,C/C++ 大学B组题解 文章目录 第1题 —— 九进制转十进制 (5分) 第2题 —— 顺子日期 (5分) 第3题 —— 刷题统计 (10分) 第4题 —— 修剪灌木 (10分) 第5题 —— X进制减法 (15分) 第6题 —— 统计子矩阵 (15分) 第7题 —— 积木画 (20分) 第8题 —— 扫雷 (20分) 第9题 —— 李白打酒加强版 (25分) 第10题 —— 砍竹子 (25分)

小哈里的博客 3354

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

2022 第十三届蓝桥杯大赛软件赛决赛, 国赛,C/C++ 大学B组题解

2022 第十三届蓝桥杯大赛软件赛决赛, 国赛,C/C++ 大学B组题解 文章目录 第1题 —— 2022 (5分) 第2题 —— 钟表 (5分) 第3题 —— 卡牌 (10分) 第4题 —— 最大数字 (10分) 第5题 —— 出差 (15分) 第6题 —— 费用报销 (15分) 第7题 —— 故障 (20分) 第8题 —— 机房 (20分) 第9题 —— 齿轮 (25分) 第10题 —— 搬砖 (25分)

小哈里的博客 2183

2022 第十三届蓝桥杯大赛软件赛省赛(第二场),C/C++ 大学B组题解

2022 第十三届蓝桥杯大赛软件赛省赛(第二场),C/C++ 大学B组题解 文章目录 第1题 —— 练习 (5分) 第2题 —— 三角回文数 (5分) 第3题 —— 卡片 (10分) 第4题 —— 考勤刷卡 (10分) 第5题 —— 最大和 (15分) 第6题 —— 染色时间 (15分) 第7题 —— k 倍区间 (20分) 第8题 —— 选素数 (20分) 第9题 —— 第几小 (25分) 第10题 —— 单峰序列 (25分)

小哈里的博客 3795

看看去年蓝桥考了什么,第十三届蓝桥杯省赛(C/C++ 大学B组)题解

看看去年蓝桥考了什么,第十三届蓝桥杯省赛(C/C++ 大学B组)题解

Ceylan__的博客 3610

2022年第十三届蓝桥杯大赛软件类决赛C/C++大学B组(国赛)题解

蓝桥杯

m0_58642116的博客 4335

第十三届蓝桥杯大赛软件赛省赛C/C++ 大学 B 组 题解

第十三届蓝桥杯大赛软件赛省赛C/C++ 大学 B 组 题解

ros275229的博客 3093

2022年第十三届蓝桥杯大赛C/C++ 大学 B 组个人题解

填空题 A: 九进制转十进制 九进制正整数 (2022)9转换成十进制等于多少? 答案 1478 AC代码 #include<iostream> #include<cmath> #define endl '\n' #define pii pair<int, int> #define ios ios::sync_with_stdio(false) #define tie cin.tie(NULL),cout.tie(NULL) using namespace std; c

Elf_yoki的博客 1786

2022年第十三届蓝桥杯软件类决赛C/C++大学B组题解

2022年第十三届蓝桥杯软件类决赛C/C++大学B组题解 1. 卡牌 2. 最大数字 3. 出差 4. 费用报销 7. 齿轮 8. 搬砖 题目及自测链接

Mr_dimple的博客 1961

第十三届蓝桥杯大赛软件赛省赛C/C++ 大学 B 组题解

5+5变2+8难度就上来了,感觉含金量会好一点 PS:线上除外,当这话没说就行 试题 A: 九进制转十进制 解析略,打卡题直接上代码 int x=2020; while(x>=9){ cout<<x%9; x/=9; } cout<<x<<endl; 试题 B: 顺子日期 目前有很多争议,分为 3 种答案:4,5,14 我考试时写的答案是 4 而比赛后当天晚上的蓝桥云课说的是 14第二种答案:4 即...

小灰QAQ的博客 1013

第十三届蓝桥杯C/C++大学B组真题题解(一)

【代码】第十三届蓝桥杯C/C++大学B组真题题解(一)

lmessi10_的博客 804

第十三届蓝桥杯大赛软件赛省赛C/C++ 大学 B 组 部分题解以及全部试题(后期会更新)

#include <bits/stdc++.h> using namespace std; int main() { int x = 2022; int a = 0, b = 1; do { a += x % 10 * b; x /= 10; b*= 9; } while (x); printf("%d\n", a); return 0; } 4 (个人题解,不代表官方) 2022 01 23 2022 12 30 20...

weixin_51634706的博客 835
上一篇: Codeforces Round #781 (Div. 2)
下一篇: Cards (置换,dp)
枉玊
博客等级 码龄6年 73粉丝 171原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值