头像

itdef

https://space.bilibili.com/18508846 && http://www.cnblogs.com/itdef && www.papamelon.com




离线:1小时前


最近来访(722)
用户头像
jimt
用户头像
algsUP
用户头像
Froggy
用户头像
ybf486
用户头像
ericmao
用户头像
DL爷爷单身
用户头像
zyitst
用户头像
理想
用户头像
carder
用户头像
fk239616
用户头像
godhands
用户头像
潘潘_the_panda
用户头像
挑战关注所有大佬
用户头像
invisible-pat.
用户头像
Cyzh
用户头像
烟火耶
用户头像
gjw444
用户头像
Deft
用户头像
Ac977
用户头像
Tequila

活动打卡代码 AcWing 1875. 贝茜的报复

itdef
2小时前
#include <bits/stdc++.h>
using namespace std;
int num[256][2];
int even(int x) { return (x & 1) == 0; }
int main() {
    int n; scanf("%d", &n);
    for (int i = 0; i < n; i++) {
    char ch; int x; cin >> ch >> x;
    if (even(x)) num[ch][0]++;
    else num[ch][1]++;
    }
    int result = 0;

    for(int B = 0; B < 2; B++) for(int E = 0; E < 2; E++) for(int S = 0; S < 2; S++) for(int I = 0; I < 2; I++)
    for(int G = 0; G < 2; G++) for(int O = 0; O < 2; O++) for(int M = 0; M < 2; M++)
    if (even((B + E + S + S + I + E) * (G + O + E + S) * (M + O + O)))
        result += num['B'][B] * num['E'][E] * num['S'][S] * num['I'][I] * num['G'][G] * num['O'][O] * num['M'][M];
    printf("%d\n", result);
    return 0;
}



活动打卡代码 AcWing 1884. COW

itdef
1天前
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <unordered_map>

#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
typedef pair <int, int> PII;
char str[maxn];
ll qianzhui[maxn], houzhui[maxn];
int main()
{
    int N;
    scanf("%d", &N);
    scanf("%s", str + 1);
    for(int i = 1 ; i <= N ; i ++)
    qianzhui[i] = qianzhui[i - 1] + (str[i] == 'C' ? 1 : 0);
    for(int i = N ; i >= 1 ; i --)
    houzhui[i] = houzhui[i + 1] + (str[i] == 'W' ? 1 : 0);
    ll res = 0;
    for(int i = 1 ; i <= N ; i ++)
    {
        if(str[i] == 'O')
        res += qianzhui[i - 1] * houzhui[i + 1];
    }
    printf("%lld\n",res);
    return 0;
}




活动打卡代码 AcWing 1904. 奶牛慢跑

itdef
3天前
#include<bits/stdc++.h>
using namespace std;
int n, x, v;
vector<int> a;
int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &x, &v);
        while (a.size() && v < a.back()) a.pop_back();
        a.push_back(v);
    }
    printf("%d", a.size());
    return 0;
}


活动打卡代码 AcWing 1945. 奶牛棒球

itdef
3天前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 1010;

int n;
int p[N];

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

    int res = 0;
    for (int i = 0; i + 2 < n; i ++ )
        for (int j = i + 1, l = j + 1, r = j + 1; j + 1 < n; j ++ )
        {
            while (l < n && p[l] - p[j] < p[j] - p[i]) l ++ ;
            while (r < n && p[r] - p[j] <= 2 * (p[j] - p[i])) r ++ ;
            res += r - l;
        }

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





itdef
3天前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

const int INF = 2e9;

int n, x, y, z;

int main()
{
    map<int, int> b;

    scanf("%d%d%d%d", &n, &x, &y, &z);
    for (int i = 0; i < n; i ++ )
    {
        int l, r;
        scanf("%d%d", &l, &r);
        b[-INF] += x;
        b[l] += y - x;
        b[r + 1] += z - y;
        b[INF] -= z;
    }

    int res = 0, sum = 0;
    for (auto& [k, v]: b)
    {
        sum += v;
        res = max(res, sum);
    }

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




活动打卡代码 AcWing 1960. 闪烁

itdef
3天前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 1 << 16;

int n;
LL m;
int p[N];

int update(int state)
{
    int res = 0;
    for (int i = 0; i < n; i ++ )
    {
        int j = (i - 1 + n) % n;
        int x = state >> i & 1, y = state >> j & 1;
        res |= (x ^ y) << i;
    }
    return res;
}

void print(int state)
{
    for (int i = 0; i < n; i ++ )
        cout << (state >> i & 1) << endl;
}

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

    int state = 0;
    for (int i = 0; i < n; i ++ )
    {
        int x;
        cin >> x;
        state |= x << i;
    }

    memset(p, -1, sizeof p);
    p[state] = 0;

    for (int i = 1;; i ++ )
    {
        state = update(state);
        if (i == m)
        {
            print(state);
            break;
        }
        else if (p[state] == -1) p[state] = i;
        else
        {
            int len = i - p[state];
            int r = (m - i) % len;
            while (r -- ) state = update(state);
            print(state);
            break;
        }
    }

    return 0;
}




活动打卡代码 AcWing 1969. 品种邻近

itdef
3天前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

const int M = 1000010;

int n, k;
int cnt[M];

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

    int res = -1;
    queue<int> q;
    for (int i = 0; i < n; i ++ )
    {
        int id;
        scanf("%d", &id);

        if (cnt[id] > 0) res = max(res, id);
        cnt[id] ++ ;
        q.push(id);
        if (q.size() > k)
        {
            cnt[q.front()] -- ;
            q.pop();
        }
    }

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




活动打卡代码 AcWing 1978. 奶牛过马路

itdef
3天前
#include <iostream>
#include <cstring>
#include <algorithm>

#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;

const int N = 100010, INF = 1e8;

int n;
PII q[N];
int smax[N], smin[N];

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

    for (int i = 1; i <= n; i ++ ) scanf("%d%d", &q[i].x, &q[i].y);

    sort(q + 1, q + n + 1);

    smax[0] = -INF, smin[n + 1] = INF;
    for (int i = 1; i <= n; i ++ ) smax[i] = max(smax[i - 1], q[i].y);
    for (int i = n; i; i -- ) smin[i] = min(smin[i + 1], q[i].y);

    int res = 0;
    for (int i = 1; i <= n; i ++ )
        if (smax[i - 1] < q[i].y && smin[i + 1] > q[i].y)
            res ++ ;

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



活动打卡代码 AcWing 1987. 粉刷栅栏

itdef
3天前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    map<int, int> b;
    int n;
    scanf("%d", &n);

    int x = 0, y;
    char s[2];
    while (n -- )
    {
        scanf("%d%s", &y, s);
        if (*s == 'R')
        {
            b[x] ++ ;
            b[x + y] -- ;
            x += y;
        }
        else
        {
            b[x - y] ++ ;
            b[x] -- ;
            x -= y;
        }
    }

    int res = 0, sum = 0, last;
    for (auto& [x, v]: b)
    {
        if (sum >= 2) res += x - last;
        sum += v;
        last = x;
    }

    printf("%d\n", res);

    return 0;
}



活动打卡代码 AcWing 1913. 公平摄影

itdef
4天前
#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> m;
int main() {
    scanf("%d", &n);
    vector< pair<int, int> > a;
    for(int i = 0; i < n; i++) {
        int x; char c; cin >> x >> c;
        if(c == 'H') a.push_back(make_pair(x, 1));
        else a.push_back(make_pair(x, -1));
    }
    sort(a.begin(), a.end());
    m[0] = 0;
    int ans_h = 0, ans_g = 0, ans_gh = 0, h = 2e9, g = 2e9, q = 0;
    for (int i = 0; i < n; i++) {
        int x = a[i].first, o = a[i].second;
        if (o == 1) h = min(h, x), ans_h = max(ans_h, x - h), g = 2e9;  //照片h
        else g = min(g, x), ans_g = max(ans_g, x - g), h = 2e9;  //照片g
        q += o;
        if(m.find(q) == m.end()) m[q] = a[i + 1].first;
        else ans_gh = max(ans_gh, x - m[q]);
    }
    printf("%d", max(ans_gh, max(ans_h, ans_g)));
    return 0;
}