头像

合计飞

中北大学




离线:8小时前


活动打卡代码 AcWing 125. 耍杂技的牛

合计飞
11小时前
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 50010;

struct Cow
{
    int w, s;

    bool operator < (const Cow &W) const
    {
        return w + s < W.w + W.s;
    }
}cows[N];
int n;
int main()
{
    scanf("%d", &n);

    for(int i = 0; i < n; i ++) 
    {
        int w, s;
        scanf("%d%d", &w, &s);
        cows[i] = {w, s};
    }

    sort(cows, cows + n);

    int ma = -2e9, x = 0;

    for(int i = 0; i < n; i ++)
    {
        ma = max(ma, x - cows[i].s);
        x += cows[i].w;
    }

    printf("%d", ma);

    return 0;
}


活动打卡代码 AcWing 104. 货仓选址

合计飞
12小时前
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 100010;

int a[N];

int main()
{
    int n;
    scanf("%d", &n);

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

    sort(a, a + n);

    int res = 0, mid = n / 2;
    for(int i = 0; i < n; i ++) res += abs(a[i] - a[mid]);

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


活动打卡代码 AcWing 913. 排队打水

合计飞
12小时前
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 100010;
typedef long long ll;

int a[N], b[N];

int main()
{
    int n;
    scanf("%d", &n);

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

    sort(a, a + n);

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

    ll res = 0;
    for(int i = 0; i < n; i ++) res += b[i];

    printf("%lld", res);

    return 0;
}


活动打卡代码 AcWing 148. 合并果子

合计飞
12小时前
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>

using namespace std;
const int N = 10010;

int a[N];

int main()
{
    int n;
    scanf("%d", &n);

    priority_queue<int, vector<int>, greater<int>> q;

    for(int i = 0; i < n; i ++) 
    {
        scanf("%d", &a[i]);
        q.push(a[i]);
    }

    int res = 0;

    while(q.size() > 1) 
    {
        int x = q.top();q.pop();
        int y = q.top();q.pop();

        res += (x + y);

        q.push(x + y);
    }

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


活动打卡代码 AcWing 907. 区间覆盖

合计飞
12小时前
#include<iostream>
#include<algorithm>

using namespace std;
const int N = 100010;

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

int main()
{
    int n, a, b;

    scanf("%d%d%d", &a, &b, &n);

    for(int i = 0; i < n; i ++) 
    {
        int l, r;
        scanf("%d%d", &l, &r);
        range[i] = {l, r};
    }

    sort(range, range + n);
    int res = 0;

    int r = -2e9;
    for(int i = 0; i < n; i ++)
    {
        int j = i;
        r = -2e9;
        while(j < n && range[j].l <= a)
        {
            r = max(r, range[j].r);
            j ++;
        }

        if(r < a)
        {
            res = -1;
            break;
        }

        res ++;
        a = r;
        i = j - 1;

        if(r >= b) break;
    }

    if(r < b) res = -1;
    printf("%d", res);
    return 0;
}


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

合计飞
13小时前
#include<iostream>
#include<queue>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;
const int N = 100010;

struct Range{
    int l, r;
    bool operator < (const Range &w) const
    {
        return l < w.l;
    }
}range[N];
int main()
{
    int n;
    scanf("%d", &n);

    for(int i = 0; i < n; i ++) 
    {
        int l, r;
        scanf("%d%d", &l, &r);
        range[i] = {l, r};
    }

    sort(range, range + n);
    priority_queue<int, vector<int>, greater<int>> heap;

    for(int i = 0; i < n; i ++)
    {
        if(heap.empty() || range[i].l <= heap.top()) heap.push(range[i].r);
        else {
            heap.pop();
            heap.push(range[i].r);
        }
    }

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



#include<iostream>
#include<algorithm>

using namespace std;
const int N = 100010;

struct Range {
    int l, r;

    bool operator < (const Range &w)const
    {
        return r < w.r;
    }
}range[N];

int main()
{
    int n;
    scanf("%d", &n);

    for(int i = 0; i < n; i ++)
    {
        int l, r;
        scanf("%d%d", &l, &r);

        range[i] = {l, r};
    }

    sort(range, range + n);

    int res = 0, end = -2e9;
    for(int i = 0; i < n; i ++)
        if(range[i].l > end)
        {
            res ++;
            end = range[i].r;
        }

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


活动打卡代码 AcWing 905. 区间选点

#include<iostream>
#include<algorithm>

using namespace std;
const int N = 100010;

struct Range {
    int l, r;

    bool operator < (const Range &w)const
    {
        return r < w.r;
    }
}range[N];

int main()
{
    int n;
    scanf("%d", &n);

    for(int i = 0; i < n; i ++)
    {
        int l, r;
        scanf("%d%d", &l, &r);

        range[i] = {l, r};
    }

    sort(range, range + n);

    int res = 0, end = -2e9;
    for(int i = 0; i < n; i ++)
        if(range[i].l > end)
        {
            res ++;
            end = range[i].r;
        }

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


活动打卡代码 AcWing 1340. 贪婪的送礼者

#include<string>
#include<vector>
#include<iostream>
#include<unordered_map>

using namespace std;

int main()
{
    vector<string> v;
    unordered_map<string, int> mp;
    int n;
    cin >> n;

    for(int i = 0; i < n; i ++)
    {
        string s;
        cin >> s;
        v.push_back(s);
        mp[s] = 0;
    }

    for(int i = 0; i < n; i ++)
    {
        string s;
        int a, b;
        cin >> s >> a >> b;

        if(b == 0) continue;
        mp[s] = mp[s] - a + a % b;
        a /= b;

        for(int i = 0; i < b; i ++)
        {
            string t;
            cin >> t;
            mp[t] += a;
        }
    }

    for(int i = 0; i < v.size(); i ++)
        cout << v[i] << " " << mp[v[i]] << endl;

    return 0;
}



#include<string>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
const int mod = 47;
const int N = 10;

int n;





int main()
{

    unordered_map<char, int> mp;
    char c = 'A';
    for(int i = 1; i <= 26; i ++)
        mp[c ++] = i;

    string s1, s2;

    cin >> s1 >> s2;

    int x = 1, y = 1;
    for(int i = 0; i < s1.size(); i ++) x = (x * mp[s1[i]]) % mod;

    for(int i = 0 ;i < s2.size(); i ++) y = (y * mp[s2[i]]) % mod;

    if(x == y) puts("GO");
    else puts("STAY");
    return 0;
}