头像

ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ




离线:2天前


最近来访(809)
用户头像
怀旧经典_3
用户头像
awhiteboy
用户头像
忘打周赛Duck
用户头像
煜y庚
用户头像
周赛
用户头像
北海没有WA
用户头像
Richard-H
用户头像
种花家的兔兔
用户头像
liaoyanxu
用户头像
DraymoNd_
用户头像
incra
用户头像
HYL_7
用户头像
Fluent
用户头像
听取WA声YI片
用户头像
wqzgg
用户头像
树枝666
用户头像
垫底抽风-小号
用户头像
xcb
用户头像
sergey
用户头像
Ethanyyc

新鲜事 原文

AcWing《Web应用课》拼团优惠!https://www.acwing.com/activity/content/introduction/1150/group_buy/118971/


新鲜事 原文

AcWing《Web应用课》拼团优惠!https://www.acwing.com/activity/content/introduction/1150/group_buy/118971/


活动打卡代码 AcWing 179. 八数码

#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>

using namespace std;

int f(string state)
{
    int res = 0;
    for (int i = 0; i < state.size(); i ++ )
        if (state[i] != 'x')
        {
            int t = state[i] - '1';
            res += abs(i / 3 - t / 3) + abs(i % 3 - t % 3);
        }
    return res;
}

string bfs(string start)
{
    int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
    char op[4] = {'u', 'r', 'd', 'l'};

    string end = "12345678x";
    unordered_map<string, int> dist;
    unordered_map<string, pair<string, char>> prev;
    priority_queue<pair<int, string>, vector<pair<int, string>>, greater<pair<int, string>>> heap;

    heap.push({f(start), start});
    dist[start] = 0;

    while (heap.size())
    {
        auto t = heap.top();
        heap.pop();

        string state = t.second;

        if (state == end) break;

        int step = dist[state];
        int x, y;
        for (int i = 0; i < state.size(); i ++ )
            if (state[i] == 'x')
            {
                x = i / 3, y = i % 3;
                break;
            }
        string source = state;
        for (int i = 0; i < 4; i ++ )
        {
            int a = x + dx[i], b = y + dy[i];
            if (a >= 0 && a < 3 && b >= 0 && b < 3)
            {
                swap(state[x * 3 + y], state[a * 3 + b]);
                if (!dist.count(state) || dist[state] > step + 1)
                {
                    dist[state] = step + 1;
                    prev[state] = {source, op[i]};
                    heap.push({dist[state] + f(state), state});
                }
                swap(state[x * 3 + y], state[a * 3 + b]);
            }
        }
    }

    string res;
    while (end != start)
    {
        res += prev[end].second;
        end = prev[end].first;
    }
    reverse(res.begin(), res.end());
    return res;
}

int main()
{
    string g, c, seq;
    while (cin >> c)
    {
        g += c;
        if (c != "x") seq += c;
    }

    int t = 0;
    for (int i = 0; i < seq.size(); i ++ )
        for (int j = i + 1; j < seq.size(); j ++ )
            if (seq[i] > seq[j])
                t ++ ;

    if (t % 2) puts("unsolvable");
    else cout << bfs(g) << endl;

    return 0;
}


新鲜事 原文

AcWing【集日历瓜分10000AC币活动】赠送1月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79225/1/030e79ad/


新鲜事 原文

AcWing【集日历瓜分10000AC币活动】赠送6月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79225/6/1f4d8dee/ AcWing【集日历瓜分10000AC币活动】赠送7月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79225/7/ba530a11/ AcWing【集日历瓜分10000AC币活动】赠送8月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79225/8/2a366d23/ AcWing【集日历瓜分10000AC币活动】赠送9月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79225/9/dfeac33f/ AcWing【集日历瓜分10000AC币活动】赠送11月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79225/11/c92c023b/ AcWing【集日历瓜分10000AC币活动】赠送12月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79225/12/d9e4caaa/


新鲜事 原文

AcWing【集日历瓜分10000AC币活动】赠送1月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79225/1/a4758da7/ AcWing【集日历瓜分10000AC币活动】赠送2月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79225/2/c701df03/ AcWing【集日历瓜分10000AC币活动】赠送3月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79225/3/d5a56155/ AcWing【集日历瓜分10000AC币活动】赠送4月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79225/4/88a228c6/ AcWing【集日历瓜分10000AC币活动】赠送5月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79225/5/e60bc4b0/


新鲜事 原文

AcWing【集日历瓜分10000AC币活动】赠送1月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79225/1/2d1ae283/


活动打卡代码 AcWing 4729. 解密

#include <cstdio>
using namespace std;

int T, m, l, r, mid;
long long n, a, b;

int main ()
{
    scanf ("%d", &T);
    while (T --)
    {
        scanf ("%lld%lld%lld", &n, &a, &b), m = n - a * b + 2;
        l = 1, r = m >> 1;
        while (l < r)
        {
            mid = l + r >> 1;
            if ((long long) mid * (m - mid) >= n)
            {
                r = mid;
            }
            else
            {
                l = mid + 1;
            }
        }
        if ((long long) l * (m - l) == n)
        {
            printf ("%d %d\n", l, m - l);
        }
        else
        {
            puts ("NO");
        }
    }
    return 0;
}


活动打卡代码 AcWing 1052. 设计密码

#include <iostream>
#include <cstring>

using namespace std;

const int N = 55, mod = 1e9 + 7;

int n, m;
char s[N];
int f[N][N], ne[N];

int main()
{
    cin >> n >> s + 1;
    m = strlen(s + 1);
    for (int i = 2, j = 0; i <= m; ++ i)
    {
        while (j && s[i] != s[j + 1]) j = ne[j];
        if (s[i] == s[j + 1]) ++ j;
        ne[i] = j;
    }
    //DP
    f[0][0] = 1;
    for (int i = 0; i < n; ++ i)
    {
        for (int j = 0; j < m; ++ j)
        {
            for (char ch = 'a'; ch <= 'z'; ++ ch)
            {
                int ptr = j;
                while (ptr && s[ptr + 1] != ch) ptr = ne[ptr];
                if (s[ptr + 1] == ch) ++ ptr;
                f[i + 1][ptr] = (f[i + 1][ptr] + f[i][j]) % mod;
            }
        }
    }
    int res = 0;
    for (int j = 0; j < m; ++ j) res = (res + f[n][j]) % mod;
    cout << res << endl;
    return 0;
}


新鲜事 原文

AcWing【集日历瓜分10000AC币活动】赠送10月日历!https://www.acwing.com/file_system/gui/taskbar/widgets/clock/calendar/send/79226/10/e971a3c7/