头像

Bigbos

NENU




离线:3小时前


最近来访(137)
用户头像
凡性的提醒
用户头像
@_龙瑞
用户头像
insistance
用户头像
冷轩
用户头像
l_y_f
用户头像
小树林
用户头像
窗外的麻雀
用户头像
15163669008
用户头像
Aigrl
用户头像
啦啦啦啦啦啦啦啦啦啦啦
用户头像
愚者迷途
用户头像
s.y.
用户头像
水狗
用户头像
柳明月清风
用户头像
77777777777
用户头像
你加里没人奥
用户头像
W_844
用户头像
psychopath_6
用户头像
不拿国一不改名
用户头像
狂气电波

活动打卡代码 LeetCode 1656. 设计有序流

Bigbos
3小时前
class OrderedStream {
public:

    vector<int> id;
    vector<string> val;
    int ptr = 0;
    int mxn;

    OrderedStream(int n) {
        id.resize(n);
        val.resize(n);
        mxn = n;
    }

    vector<string> insert(int idKey, string value) {
        idKey --;
        id[idKey] = 1;
        val[idKey] = value;

        vector<string> res;
        while (ptr < mxn && id[ptr]) {
            res.push_back(val[ptr]);
            ptr ++;
        }

        return res;
    }
};

/**
 * Your OrderedStream object will be instantiated and called as such:
 * OrderedStream* obj = new OrderedStream(n);
 * vector<string> param_1 = obj->insert(idKey,value);
 */


活动打卡代码 AcWing 4508. 移动的点

Bigbos
2天前
#include <bits/stdc++.h>

#define fi first
#define se second

using namespace std;

using i64 = long long;

constexpr int inf = 0x3f3f3f3f;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    i64 n, a, b;
    cin >> n >> a >> b;

    i64 ans = 0;
    map<i64, i64> cnt;
    map<i64, map<i64, i64>> v;
    for (int i = 0; i < n; i++) {
        i64 x, vx, vy;
        cin >> x >> vx >> vy;
        ans += cnt[vy - a * vx] - v[vx][vy];
        cnt[vy - a * vx] ++;
        v[vx][vy] ++;
    }

    /*
    x1 + vx1 * t = x2 + vx2 * t
    y1 + vy1 * t = y2 + vy2 * t

    y1 = a * x1 + b
    y2 = a * x2 + b

    (x1 - x2) / (vx2 - vx1) = (y1 - y2) / (vy2 - vy1)
    (x1 - x2) * (vy2 - vy1) = (y1 - y2) * (vx2 - vx1)

    (x1 - x2) * (vy2 - vy1) = a * (x1 - x2) * (vx2 - vx1)
    (vy2 - vy1) = a * (vx2 - vx1)
    vy2 - a * vx2 = vy1 - a * vx1


    */


    cout << ans * 2 << "\n";

    return 0;
}


活动打卡代码 LeetCode 1282. 用户分组

Bigbos
4天前
class Solution {
public:
    vector<vector<int>> groupThePeople(vector<int>& groupSizes) {
        vector<vector<int>> res;
        vector<pair<int, int>> t;
        for (int i = 0; i < groupSizes.size(); i++) {
            t.push_back({groupSizes[i], i});
        }

        stable_sort(t.begin(), t.end(), [&] (auto a, auto b) {
            return a.first > b.first;
        });

        for (int i = 0; i < t.size(); i++) {
            if (res.empty() || res.back().size() >= t[i].first) {
                vector<int> tmp;
                tmp.push_back(t[i].second);
                res.push_back(tmp);
            } else {
                res.back().push_back(t[i].second);
            }
        }

        return res;
    }
};



Bigbos
4天前
#include <bits/stdc++.h>

int main() {
    int a, b;
    std::cin >> a >> b;

    std::cout << a + b << "\n";

    return 0;
}



Bigbos
5天前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>

using namespace std;

int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {

    int Y, M, D;
    while (cin >> Y >> M >> D) {
        int day = 0;
        for (int i = 1; i <= M - 1; i++)
            day += mon[i];

        cout << day + D + (M > 2 ? int((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) : 0) << "\n";
    }

    return 0;
}


活动打卡代码 AcWing 3593. 统计单词

Bigbos
5天前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>

using namespace std;

int main() {
    string s;
    while (cin >> s) {
        cout << s.size() - (s[s.size() - 1] == '.') << " ";
    }

    return 0;
}


活动打卡代码 AcWing 3452. 进制转换

Bigbos
5天前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>

using namespace std;

int main() {
    string s;
    while (cin >> s) {
        int res = 0;
        for (int i = 2 + (s[0] == '-'); i < s.size(); i++)    
            if (s[i] >= 'A' && s[i] <= 'Z')
                res = res * 16 + s[i] - 'A' + 10;
            else if (s[i] >= 'a' && s[i] <= 'z') {
                res = res * 16 + s[i] - 'a' + 10;            
            } else
                res = res * 16 + s[i] - '0';

        cout << res * (s[0] == '-' ? -1 : 1) << "\n";
    }

    return 0;
}


活动打卡代码 AcWing 3667. 切木棍

Bigbos
5天前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>

using namespace std;

int main()
{

    int n;
    while (cin >> n) {
        if (n & 1 || n == 0)
            cout << 0 << "\n";
        else {
            n /= 2;
            /*0 1 2 3 4 5 6 7*/
            cout << (n - 1) / 2 << "\n";
        }
    }

    return 0;
}


活动打卡代码 AcWing 2070. 自行车之旅

Bigbos
5天前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main() {
    int _;
    int t = 0;
    for (cin >> _; _; _--) {
        cout << "Case #" << ++t << ": ";

        int n;
        cin >> n;

        vector<int> h(n);
        for (auto &hi : h)
            cin >> hi;

        int res = 0;
        for (int i = 1; i + 1 < n; i++)
            if (h[i] > h[i - 1] && h[i] > h[i + 1])
                res ++;

        cout << res << "\n";
    }

    return 0;
}



Bigbos
6天前

AcWing 4546. 最大和加强加强版


状态表示:$f(i,j,0/1)$表示由前$i$个数字构成$j$个区间,且第$i$个数取或不取的最大值

状态转移:$f(i,j,0) = max(f(i-1,j,0),f(i-1,j,1))$,$f(i,j,1) = max(f(i-1,j,1),max(f(i-1,j-1,1),f(i-1,j-1,0))) + w[i]$

加亿点点优化就过了


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define fi first
#define se second

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)

using namespace std;

using i64 = long long;

constexpr int inf = 0x3f3f3f3f, N = 1E6 + 5;

int s[N];
i64 dp[2][1005][2];

void inline read(int& x) {
    x = 0;
    int f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
        x = x * 10 + (c - '0'), c = getchar();
    x *= f;
}

int main() {

    int m, n;
    while (~scanf("%d%d", &m, &n)) {
        for (int i = 1; i <= n; i++)
            read(s[i]);

        memset(dp, -0x3f, sizeof dp);
        dp[0][0][0] = 0;

        for (int i = 1; i <= n; i++) {
            int pre = i - 1 & 1, cur = i & 1;
            dp[cur][0][0] = 0;
            for (int j = 1; j <= min(i, m); j++) {
                dp[cur][j][0] = max(dp[pre][j][1], dp[pre][j][0]);
                dp[cur][j][1] = max(dp[pre][j][1], max(dp[pre][j - 1][0], dp[pre][j - 1][1])) + s[i];
            }
        }

        printf("%lld\n", max(dp[n & 1][m][1], dp[n & 1][m][0]));
    }

    return 0;
}