头像

TheXX

NJUPT




离线:4天前


最近来访(56)
用户头像
lixiaoqian_qwq
用户头像
陌丨落
用户头像
Hacker_King
用户头像
c05
用户头像
LonelyLove
用户头像
小镇ac不了家
用户头像
fy张美星
用户头像
起床靠毅力
用户头像
AcPlease
用户头像
风不会停息_6
用户头像
.Alex.
用户头像
用户头像
zc2077
用户头像
V1
用户头像
wv
用户头像
yuanheci
用户头像
野蛮生长
用户头像
KillLemon
用户头像
就是个弟弟
用户头像
LcCcY


TheXX
6天前
#include <assert.h>

char* strcpy(char* dst, const char* src)
{
    assert(dst != NULL && src != NULL);
    char* res = dst;
    while ((*dst++ = *src++) != '\0');
    return res;
}

int strlen(char* str)
{
    assert(str != NULL);
    int len = 0;
    while ((*str++) != '\0')
        ++len;
    return len;
}

int strcmp(const char *s1, const char *s2)
{
    assert(s1 != NULL && s2 != NULL);
    while (*s1 == *s2) {
        if (*s1 == '\0')
            return 0;
        s1++, s2++;
    }
    return *s1 - *s2;
}

char* strcat(char* dst, const char* src)
{
    assert(dst != NULL && src != NULL);
    char* res = dst;
    while (*dst != '\0')
        ++dst;
    while (*dst++ = *src++);
    return res;
}



分享 C++ split

TheXX
3个月前

C++ split by char

#include <string>
#include <sstream>
#include <vector>
std::vector<std::string> split(const std::string &s, char delim) {
  std::stringstream ss(s);
  std::string item;
  std::vector<std::string> elems;
  while (std::getline(ss, item, delim)) {
    elems.push_back(item);
  }
  return elems;
}

C++ split by string

#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

// for string delimiter
vector<string> split (string s, string delimiter) {
    size_t pos_start = 0, pos_end, delim_len = delimiter.length();
    string token;
    vector<string> res;

    while ((pos_end = s.find (delimiter, pos_start)) != string::npos) {
        token = s.substr (pos_start, pos_end - pos_start);
        pos_start = pos_end + delim_len;
        res.push_back (token);
    }

    res.push_back (s.substr (pos_start));
    return res;
}



活动打卡代码 AcWing 1812. 方形牧场

TheXX
3个月前
#include <iostream>
using namespace std;

typedef pair<int, int> PII;

PII a, b, c, d;

int main()
{
    cin >> a.first >> a.second >> b.first >> b.second;
    cin >> c.first >> c.second >> d.first >> d.second;

    PII x = {min(a.first, c.first), min(a.second, c.second)};
    PII y = {max(b.first, d.first), max(b.second, d.second)};

    int len = max(abs(x.first - y.first), abs(x.second - y.second));

    cout << len * len << endl;

    return 0;
}


活动打卡代码 AcWing 1470. 水桶传递队列

TheXX
4个月前
#include <iostream>
#include <cstring>
using namespace std;

typedef pair<int, int> PII;
const int N = 15;

PII q[N * N];
int front = -1, rear = -1;
char g[N][N];
int dist[N][N];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

int bfs(PII start, PII end)
{
    memset(dist, -1, sizeof dist);
    q[++rear] = start;
    dist[start.first][start.second] = 0;

    while (front != rear) {
        PII u = q[++front];
        int x = u.first, y = u.second;
        for (int i = 0; i < 4; ++i) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx >= 0 && nx < 10 && ny >= 0 && ny < 10 && dist[nx][ny] == -1 && g[nx][ny] != 'R') {
                dist[nx][ny] = dist[x][y] + 1;
                q[++rear] = {nx, ny};
            }
            if (nx == end.first && ny == end.second)
                return dist[nx][ny];
        }

    }


    return dist[end.first][end.second];
}

int main()
{
    for (int i = 0; i < 10; ++i)
        scanf("%s", g[i]);

    PII start, end;
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            if (g[i][j] == 'B')
                start = {i, j};
            if (g[i][j] == 'L')
                end = {i, j};
        }
    }

    int res = bfs(start, end) - 1;

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


活动打卡代码 AcWing 1683. 困牛放牧

TheXX
4个月前
#include <iostream>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    a = min(a, min(b, c));
    c = max(c, max(a, b));
    b = a + b + c - a - c;

    if (a + 2 == c)
        cout << 0 << endl;
    else if (b + 2 == c || a + 2 == b)
        cout << 1 << endl;
    else
        cout << 2 << endl;
    cout << max(b - a, c - b) - 1 << endl;
    return 0;
}


活动打卡代码 AcWing 1714. 混合牛奶

TheXX
4个月前
#include <iostream>

using namespace std;

const int N = 5;

typedef pair<int, int> PII;
PII bucket[N];

int main()
{
    int c, m;
    for (int i = 0; i < 3; ++i) {
        cin >> c >> m;
        bucket[i] = {c, m};
    }

    for (int i = 0; i < 100; ++i) {
        int &c1 = bucket[i % 3].first, &m1 = bucket[i % 3].second;
        int &c2 = bucket[(i + 1) % 3].first, &m2 = bucket[(i + 1) % 3].second;

        int d = c2 - m2;
        m2 = d >= m1 ? m2 + m1 : c2; 
        m1 = d >= m1 ? 0 : m1 - d;

    }

    for (int i = 0; i < 3; ++i)
        cout << bucket[i].second << endl;
    return 0;
}


活动打卡代码 AcWing 1671. 三角形

TheXX
4个月前
#include <iostream>
using namespace std;

typedef pair<int, int> PII;
const int N = 110;
PII cod[N];

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        cod[i] = {x, y};
    }

    int res = 0;
    for (int i = 0; i < n; ++i) {
        int x1 = cod[i].first, y1 = cod[i].second;
        int hight = 0, wid = 0;
        for (int j = 0; j < n; ++j) {
            int x2 = cod[j].first, y2 = cod[j].second;
            if (x1 == x2)
                hight = max(hight, abs(y1 - y2));
            if (y1 == y2)
                wid = max(wid, abs(x1 - x2));
        }
        res = max(res, hight * wid);
    }

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


活动打卡代码 AcWing 1442. 单词处理器

TheXX
4个月前
#include <iostream>
using namespace std;

const int N = 110;
string words[N];

int main()
{
    int n, k;
    cin >> n >> k;

    for (int i = 0; i < n; ++i)
        cin >> words[i];

    for (int i = 0; i < n; ++i) {
        int j = i, cnt = k;
        string line;
        while (j < n && words[j].size() <= cnt) {
            line += words[j] + ' ';
            cnt -= words[j++].size();
        }
        line.pop_back();
        cout << line << endl;
        i = j - 1;
    }

    return 0;
}


活动打卡代码 AcWing 1459. 奶牛体操

TheXX
4个月前
#include <iostream>
using namespace std;

const int N = 25;
int cnt[N][N];
int seq[N];
int n, k;

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

    int res = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            if (cnt[i][j] == k)
                res++;

    cout << res << endl;
    return 0;
}


活动打卡代码 AcWing 3745. 牛的学术圈 I

TheXX
4个月前
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 100010;
int a[N];

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);

    int l = 0, r = n;
    while (l < r) {
        int mid = l + r + 1 >> 1;
        int cnt = 0, s = k;
        for (int i = 0; i < n; ++i)
            if (a[i] >= mid)
                cnt++;
            else if (s && a[i] + 1 == mid)
                cnt++, s--;
        if (cnt >= mid)
            l = mid;
        else
            r = mid - 1;
    }

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