头像

vcrlwpx

TYNFMS https://tynfms.github.io/ https://www.wwli.asia/downloads/books/Al-jabr-1.pdf




离线:1天前


最近来访(163)
用户头像
𝕮𝖗𝖞𝕭𝖆𝖇𝖞._5
用户头像
wangwu
用户头像
dxh
用户头像
天元之弈
用户头像
昨天你TLE了吗
用户头像
孙笑川爱xgj
用户头像
waver_rui
用户头像
磨糖_fly
用户头像
北边小洛
用户头像
Hicode002
用户头像
Thelittleprince
用户头像
单南松
用户头像
Aa一块二
用户头像
Fatin
用户头像
acwing_陈
用户头像
躺平少年
用户头像
冰之韵
用户头像
夜寐
用户头像
垫底抽風
用户头像
李.嘉图

活动打卡代码 AcWing 3302. 表达式求值

vcrlwpx
8天前
#include <bits/stdc++.h>
using namespace std;

const int N = 100010;
string s;
int nstk[N], ntop, ctop;
char cstk[N];
int f[128];

void init() {
    f['('] = 1, f[')'] = 2, f['+'] = f['-'] = 3,
    f['*'] = f['/'] = 4, f['^'] = 5;
}

int qpow(int a, int p) {
    int res = 1;
    while (p) {
        if (p & 1) res *= a;
        a *= a;
        p >>= 1;
    }
    return res;
}

int calc(int x, int y, char c) {
    if (c == '+') return x + y;
    if (c == '-') return x - y;
    if (c == '*') return x * y;
    if (c == '/') return x / y;
    if (c == '^') return qpow(x, y);
}

int main() {
    init();

    cin >> s;
    s = "(" + s + ")";
    int len = s.length(), i = 0;

    while (i < len) {
        if (isdigit(s[i])) {
            int x = 0;
            while (isdigit(s[i]))
                x = x * 10 + (s[i] - 48), i++;
            nstk[++ntop] = x;
        } else if (s[i] == '(' || f[s[i]] > f[cstk[ctop]]) {
            cstk[++ctop] = s[i], i++;
            if (cstk[ctop] == ')') ctop -= 2;
        } else {
            nstk[ntop - 1] = calc(nstk[ntop - 1], nstk[ntop], cstk[ctop]);
            ntop--, ctop--;
        }
    }

    printf("%d\n", nstk[1]);

    return 0;
}



活动打卡代码 AcWing 95. 费解的开关

vcrlwpx
1个月前
#include <bits/stdc++.h>
using namespace std;

bool f[7][7], g[7][7];

void translate(int i, int j) {
    f[i][j] ^= 1;
    f[i - 1][j] ^= 1;
    f[i][j - 1] ^= 1;
    f[i + 1][j] ^= 1;
    f[i][j + 1] ^= 1;
}

void work() {
    char c = getchar();
    int res = 114514, val;

    for (int i = 1; i <= 5; i++)
        for (int j = 1; j <= 5; j++) {
            while (!isdigit(c)) c = getchar();
            g[i][j] = (int)c ^ 48;
            c = getchar();
        }

    for (int k = 0; k < 32; k++) {
        val = 0;
        memcpy(f, g, sizeof(f));

        for (int i = 1; i <= 5; i++)
            if (k >> (i - 1) & 1) 
                translate(1, i), val++;

        for (int i = 2; i <= 5; i++)
            for (int j = 1; j <= 5; j++)
                if (!f[i - 1][j]) 
                    translate(i, j), val++;

        bool flag = 1;
        for (int i = 1; i <= 5; i++)
            if (!f[5][i]) flag = 0;

        if (flag && val < res) res = val; 
    }

    if (res > 6) printf("-1\n");
    else printf("%d\n", res);
}

int main() {
    int tt;
    cin >> tt;
    while (tt--)
        work();

    return 0;
}


活动打卡代码 AcWing 96. 奇怪的汉诺塔

vcrlwpx
1个月前
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 25;
ll f[N], g[N];

int main() {
    f[1] = 1;
    for (int i = 1; i <= 12; i++)
        f[i] = 2 * f[i - 1] + 1;

    memset(g, 0x3f, sizeof(g));
    g[1] = 1, g[2] = 3;
    for (int i = 3; i <= 12; i++)
        for (int j = 1; j < i; j++)
            g[i] = min(g[i], 2 * g[j] + f[i - j]);

    for (int i = 1; i <= 12; i++)
        cout << g[i] << endl;

    return 0;
}


新鲜事 原文

vcrlwpx
5个月前
住了两年校,发现把以前打的码全忘了 在中考,暑假再回看吧


活动打卡代码 AcWing 275. 传纸条

vcrlwpx
11个月前
// Problem: 传纸条
// Contest: AcWing
// URL: https://www.acwing.com/problem/content/277/
// Memory Limit: 64 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 60;
int g[N][N], f[N << 1][N][N];
int n, m;

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> g[i][j];

    for (int k = 2; k <= n + m; k++)
        for (int x1 = max(1, k - m); x1 <= n && x1 < k; x1++) // 1 <= y1 = k - x1 <= m, 1 <= x1 <= n => 1 1
            for (int x2 = max(1, k - m); x2 <= n && x2 < k; x2++) 
                for (int a = 0; a <= 1; a++)
                    for (int b = 0; b <= 1; b++) {
                        int y1 = k - x1, y2 = k - x2;
                        int tmp = g[x1][y1];
                        if (x1 != x2 || k == 2 || k == n + m) {
                            tmp += g[x2][y2];
                            f[k][x1][x2] = max(f[k][x1][x2], f[k - 1][x1 - a][x2 - b] + tmp);
                        }
                    }
            // {
                // if (x1 == x2) continue;
                // int y1 = k - x1, y2 = k - x2;
                // // (x1 - 1, y1), (x2 - 1, y2)
                // // (x1, y1 - 1), (x2 - 1, y2)
                // // (x1 - 1, y1), (x2, y2 - 1)
                // // (x1, y1 - 1), (x2, y2 - 1)
                // f[k][x1][x2] = max(f[k][x1][x2], f[k - 1][x1 - 1][x2 - 1]);
                // f[k][x1][x2] = max(f[k][x1][x2], f[k - 1][x1][x2 - 1]); 
                // f[k][x1][x2] = max(f[k][x1][x2], f[k - 1][x1 - 1][x2]);
                // f[k][x1][x2] = max(f[k][x1][x2], f[k - 1][x1][x2]);
                // f[k][x1][x2] += g[x1][y1] + g[x2][y2];
            // } 

    cout << f[n + m][n][n] << endl;

    return 0;
}



活动打卡代码 AcWing 274. 移动服务

vcrlwpx
11个月前
// Problem: 移动服务
// Contest: AcWing
// URL: https://www.acwing.com/problem/content/276/
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 210, M = 1010;
const int INF = 0x3f3f3f3f;
int g[N][N], n, m;
int request[M];
int f[M][N][N];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            scanf("%d", &g[i][j]);
    for (int i = 1; i <= m; i++)
        scanf("%d", request + i);

    request[0] = 3;
    memset(f, 0x3f, sizeof(f));
    f[0][1][2] = 0;
    for (int i = 0; i < m; i++) 
        for (int x = 1; x <= n; x++)
            for (int y = 1; y <= n; y++) {
                int z = request[i], v = f[i][x][y];
                if (x == y || y == z || z == x) continue;
                int u = request[i + 1];
                f[i + 1][y][z] = min(f[i + 1][y][z], v + g[x][u]);
                f[i + 1][x][z] = min(f[i + 1][x][z], v + g[y][u]);
                f[i + 1][x][y] = min(f[i + 1][x][y], v + g[z][u]);
            }

    int res = INF;
    for (int x = 1; x <= n; x++)
        for (int y = 1; y <= n; y++) {
            int z = request[m];
            if (x == y || y == z || z == x) continue;
            res = min(res, f[m][x][y]);
        }
    printf("%d\n", res);

    return 0;
}



活动打卡代码 AcWing 273. 分级

vcrlwpx
11个月前
// Problem: 分级
// Contest: AcWing
// URL: https://www.acwing.com/problem/content/275/
// Memory Limit: 64 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 2010;
const int INF = 0x3f3f3f3f;
int a[N], n, b[N];
int f[N][N];

int solve() {
    for (int i = 1; i <= n; i++) {
        int minv = INF;
        for (int j = 1; j <= n; j++) {
            minv = min(minv, f[i - 1][j]);
            f[i][j] = minv + abs(a[i] - b[j]);
        }
    }

    int res = INF;
    for (int i = 1; i <= n; i++)
        res = min(res, f[n][i]);
    return res;
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }

    sort(b + 1, b + n + 1);
    int res = solve();
    reverse(a + 1, a + n + 1);
    res = min(res, solve());

    cout << res << endl;

    return 0;
}




vcrlwpx
11个月前
// Problem: 最长公共上升子序列
// Contest: AcWing
// URL: https://www.acwing.com/problem/content/274/
// Memory Limit: 64 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 3010;
int f[N][N], n, a[N], b[N];

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> b[i];

    for (int i = 1; i <= n; i++) {
        int maxv = 1;
        for (int j = 1; j <= n; j++) {
            f[i][j] = f[i - 1][j];
            if (a[i] == b[j]) f[i][j] = max(f[i][j], maxv);
            if (a[i] > b[j]) maxv = max(maxv, f[i - 1][j] + 1);
        }
    }

    int res = 0;
    for (int i = 1; i <= n; i++)
        res = max(res, f[n][i]);
    cout << res << endl;

    return 0;
}



vcrlwpx
11个月前
// Problem: 杨老师的照相排列
// Contest: AcWing
// URL: https://www.acwing.com/problem/content/273/
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N = 31;
int n, a[N];
ll f[N][N][N][N][N];

int main() {
    while (cin >> n && n) {
        memset(a, 0, sizeof(a));
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        memset(f, 0, sizeof(f));
        f[0][0][0][0][0] = 1;

        for (int a1 = 0; a1 <= a[1]; a1++)
            for (int a2 = 0; a2 <= min(a1, a[2]); a2++)
                for (int a3 = 0; a3 <= min(a2, a[3]); a3++) 
                    for (int a4 = 0; a4 <= min(a3, a[4]); a4++) 
                        for (int a5 = 0; a5 <= min(a4, a[5]); a5++) {
                            ll &x = f[a1][a2][a3][a4][a5]; 
                            if (a1 && a1 - 1 >= a2) x += f[a1 - 1][a2][a3][a4][a5];
                            if (a2 && a2 - 1 >= a3) x += f[a1][a2 - 1][a3][a4][a5];
                            if (a3 && a3 - 1 >= a4) x += f[a1][a2][a3 - 1][a4][a5];
                            if (a4 && a4 - 1 >= a5) x += f[a1][a2][a3][a4 - 1][a5];
                            if (a5)                 x += f[a1][a2][a3][a4][a5 - 1];
                        }

        cout << f[a[1]][a[2]][a[3]][a[4]][a[5]] << endl;
    }

    return 0;
}


活动打卡代码 AcWing 529. 宝藏

vcrlwpx
2021-08-30 09:42
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 12, M = 1 << N;
const int INF = 0x3f3f3f3f;
int n, m;
int d[N][N];
int f[M][N], g[M];

int main() {
    cin >> n >> m;

    memset(d, 0x3f, sizeof(d));
    for (int i = 0; i < n; i++)
        d[i][i] = 0;

    while (m--) {
        int x, y, z;
        cin >> x >> y >> z;
        x--, y--;
        d[x][y] = d[y][x] = min(d[x][y], z);
    }

    for (int i = 1; i < 1 << n; i++)
        for (int j = 0; j < n; j++) 
            if (i >> j & 1) {
                for (int k = 0; k < n; k++)
                    if (d[j][k] != INF)
                        g[i] |= 1 << k;
            }

    memset(f, 0x3f, sizeof(f));
    for (int i = 0; i < n; i++)
        f[1 << i][0] = 0;

    for (int i = 1; i < 1 << n; i++)
        for (int j = i - 1 & i; j; j = (j - 1) & i) 
            if ((g[j] & i) == i) {
                int rest = i ^ j;
                int cost = 0;
                for (int k = 0; k < n; k++)
                    if (rest >> k & 1) {
                        int t = INF;
                        for (int x = 0; x < n; x++)
                            if (j >> x & 1)
                                t = min(t, d[k][x]);
                        cost += t;
                    }

                for (int k = 1; k < n; k++)
                    f[i][k] = min(f[i][k], f[j][k - 1] + cost * k);
            }

    int res = INF;
    for (int i = 0; i < n; i++)
        res = min(res, f[(1 << n) - 1][i]);
    cout << res << endl;

    return 0;
}