头像

HUSTzyk

华中科技大学




离线:4天前


最近来访(85)
用户头像
UNIT
用户头像
acwing_6153
用户头像
独酿泉光
用户头像
zhs12345
用户头像
Aro
用户头像
-瑾年
用户头像
Jayjingle
用户头像
ZMXJ
用户头像
星海北辰
用户头像
Yuki13
用户头像
殇ベ_无寂
用户头像
宿送
用户头像
keatsli
用户头像
ONROAD
用户头像
195856
用户头像
wqzgg
用户头像
酒肉
用户头像
Nobody_Z
用户头像
金科王彦祖
用户头像
春和景明_4


HUSTzyk
1个月前

二分例题-蓝桥杯每日一题

#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_set>

using namespace std;

int n;
string str;
unordered_set<string> S;

bool check(int mid)
{
    S.clear();
    for (int i = 0; i + mid - 1 < n; i ++ )
    {
        string s = str.substr(i, mid);
        if (S.count(s)) return false;
        S.insert(s);
    }

    return true;
}

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

    int l = 1, r = n;
    while (l < r)
    {
        int mid = l + r >> 1;
        if (check(mid)) r = mid;
        else l = mid + 1;
    }

    cout << r << endl;

    return 0;
}



HUSTzyk
1个月前

增减数列

#include <iostream>

using namespace std;

typedef long long LL;

const int N = 100010;

LL n, p = 0, q = 0;
LL a[N];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i ++ ) cin >> a[i];
    for(int i = 2; i <= n; i ++ )
    {
        int c = a[i] - a[i - 1];
        if(c > 0) p += c;
        else q += -c;
    }
    cout << max(p, q) << endl << abs(p - 1) + 1 << endl;

    return 0;
}



HUSTzyk
1个月前

请问为什么memset中是(n + 1) * 4呢??
各位大佬救救本人菜🐔





HUSTzyk
1个月前

蓝桥杯-每日一题

#include<iostream>
#include<cstdio>

using namespace std;

const int N = 1e3 + 10;

int n, m, q;
int a[N][N], b[N][N];

void insert(int x1, int y1, int x2, int y2, int c)
{
    b[x1][y1] += c;
    b[x2 + 1][y1] -= c;
    b[x1][y2 + 1] -= c;
    b[x2 + 1][y2 + 1] += c;
}

int main(void)
{
    // cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> q;
    for(int i = 1; i <= n; i ++ )
        for(int j = 1; j <= m; j ++ )
            cin >> a[i][j];

    //构建差分数组
    for(int i = 1; i <= n; i ++ )
    {
        for(int j = 1; j <= m; j ++ )
        {
            insert(i, j, i, j, a[i][j]);
        }
    }

    while(q -- )
    {
        int x1, y1, x2, y2, c;
        cin >> x1 >> y1 >> x2 >> y2 >> c;
        insert(x1, y1, x2, y2, c);
    }

    //二维前缀和
    for(int i = 1; i <= n; i ++ )
    {
        for(int j = 1; j <= m; j ++)
        {
            b[i][j] += b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
        }
    }

    for(int i = 1; i <= n; i ++ )
    {
        for(int j = 1; j <= m; j ++ )
        {
            printf("%d ", b[i][j]);
        }
        printf("\n");
    }

    return 0;
} 



HUSTzyk
1个月前

蓝桥杯每日一题

#include<iostream>

using namespace std;

const int N = 100010;

int n, m;
int a[N], b[N];

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

    int l, r, c;
    while(m -- )
    {
        cin >> l >> r >> c;
        b[l] += c;
        b[r + 1] -= c;
    }

    for(int i = 1; i <= n; i ++ )
    {
        a[i] = b[i] + a[i - 1];
        cout << a[i] << ' ';
    }

    return 0;
}



HUSTzyk
1个月前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 2 * 10e5 + 10;

int n, a[N];

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

        int l = N;
        for(int i = n; i >= 1; i--)
        {
            l = min(l, i - a[i] + 1);
            if(l <= i) a[i] = 1;
        }

        for(int i = 1; i <= n; i++) cout << a[i] << " ";
        cout << endl;
    }
    return 0;
}



HUSTzyk
1个月前

子矩阵的和-(正宗y总代码!!)

#include<iostream>

using namespace std;

const int N = 1010;

int n, m, q;
int a[N][N], s[N][N];

int main()
{
    scanf("%d%d%d", &n, &m, &q);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            scanf("%d", &a[i][j]);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];

    while( q -- )
    {
        int x1, y1, x2, y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        printf("%d\n", s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1]);
    }

    return 0;
}



HUSTzyk
1个月前
#include<iostream>

using namespace std;

const int N = 1e6 + 10;

int n, m;
int s[N];

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++ )
    {
        int x;
        cin >> x;
        s[i] = s[i - 1] + x;
    }

    while(m -- )
    {
        int l, r;
        cin >> l >> r;
        cout << s[r] - s[l - 1] << endl;
    }

    return 0;
}



HUSTzyk
1个月前

截断数组(每日一题)

#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long LL;

const int N = 100010;

int n, s[N];

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++ )
    {
        int x;
        scanf("%d", &x);
        s[i] = s[i - 1] + x;
    }

    if(s[n] % 3) puts("0");
    else
    {
        LL res = 0, cnt = 0;
        for(int j = 2; j < n; j ++ )
        {
            if(s[j - 1] == s[n] / 3) cnt ++ ;
            if(s[j] == s[n] / 3 * 2) res += cnt;
        }

        printf("%lld\n", res);
    }

    return 0;
}


活动打卡代码 AcWing 906. 区间分组

HUSTzyk
2个月前

区间分组

#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

const int N = 100010;

int n;
struct Range
{
    int l, r;
    bool operator< (const Range &W)
    {
        return l < W.l;
    }
} ranges[N];

int main()
{
    cin >> n;

    for(int i = 0; i < n; i ++ )
    {
        int l, r;
        cin >> l >> r;
        ranges[i] = {l, r};
    }

    sort(ranges, ranges + n);

    priority_queue<int, vector<int>, greater<int>> heap;
    for(int i = 0; i < n; i ++ )
    {
        auto r = ranges[i];
        if(heap.empty() || heap.top() >= r.l) heap.push(r.r);
        else
        {
            int t = heap.top();
            heap.pop();
            heap.push(r.r);
        }
    }

    printf("%d\n", heap.size());

    return 0;
}