20250717

发布于:2025-07-24 ⋅ 阅读:(18) ⋅ 点赞:(0)

https://codeforces.com/problemset/problem/2112/C

#include <bits/stdc++.h>
using namespace std;

#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define int long long

typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<int, double> PID;

const int N = 5e3 + 10, INF = 0x3f3f3f3f;
int n;
int a[N];

void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    int ans = 0;
    for (int i = 1; i <= n - 2; i++)
        for (int j = i + 1; j <= n - 1; j++)
        {
            int tmp = a[i] + a[j];
            int l1;
            int l = j + 1, r = n;
            while (l < r)
            {
                int mid = l + r >> 1;
                if (tmp + a[mid] <= a[n])
                    l = mid + 1;
                else
                    r = mid;
            }
            l1 = l;
            if(tmp + a[l1] <= a[n])
            {
                continue;
            }
            l = l1, r = n;
            while (l < r)
            {
                int mid = (l + r + 1) >> 1;
                if (tmp <= a[mid])
                    r = mid - 1;
                else
                    l = mid;
            }
            if(tmp <= a[l])
            {
                continue;
            }
            ans += l - l1 + 1;
        }
    cout << ans << '\n';
}

signed main()
{
    IOS;
    int T = 1;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

牛客网-该题目为付费比赛题目,请购买后查看 


/*
因为我们找的是连续的1串,那么1串怎么才能不连续呢,说明有一个1前面是0,即01是一类
因为我们存在-1的情况,我们如何才能构成呢?
即 -1-1 01 0-1 -11 然后因为存在次方的问题,所以能够直接计算
*/
#include <bits/stdc++.h>
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define lowbit(x) (x & (-x))
#define int long long

typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<int, double> PID;

const int N = 5e5 + 10, INF = 0x3f3f3f3f, mod = 998244353;
int n;
int a[N];

int qpow(int a, int k)
{
    int ans = 1;
    while (k)
    {
        if ((k & 1))
            ans = ans * a % mod;
        a = a * a % mod;
        k >>= 1;
    }
    return ans;
}

void solve()
{
    cin >> n;
    int num = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] == -1)
            num++;
    }
    a[0] = 0;
    int ans = 0;
    for (int i = 0; i < n; i++)
        if (a[i] == 0 && a[i + 1] == 1)
            ans = ans + qpow(2, num) % mod;
        else if (a[i] == -1 && a[i + 1] == 1)
            ans = ans + qpow(2, num - 1) % mod;
        else if (a[i] == -1 && a[i + 1] == -1)
            ans = ans + qpow(2, num - 2) % mod;
        else if (a[i] == 0 && a[i + 1] == -1)
            ans = ans + qpow(2, num - 1) % mod;
    cout << ans % mod<< '\n';
}

signed main()
{
    IOS;
    int T = 1;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

 牛客网-该题目为付费比赛题目,请购买后查看

/*
思维题
*/
#include<bits/stdc++.h>
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lowbit(x) (x & (-x))
#define int long long

typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<int, double> PID;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;
int n;

void solve()
{
    int a, b;
    cin >> a >> b;
    if(a == 1 || b == 1) cout << -1 << '\n';
    else
        cout << 1 << '\n';
}

signed main()
{
    IOS;
    int T = 1;
    cin >> T;
    while(T --)
        solve();
    return 0;
}

牛客网-该题目为付费比赛题目,请购买后查看

#include <bits/stdc++.h>
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define lowbit(x) (x & (-x))
#define int long long

typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<int, double> PID;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;
int n;
int a[100];
int num[100];

void check(int k)
{
    int i = 0;
    while (k)
    {
        if ((k & 1) == 1)
            num[i]++;
        k >>= 1;
        i++;
    }
}

void solve()
{
    //     cin >> n;
    scanf("%lld", &n);
    memset(num, 0, sizeof num);
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
        check(a[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        int h = log2(a[i]);
        if (num[h] != 1)
        {
            printf("NO\n");
            return;
        }
    }
    printf("YES\n");
}

signed main()
{
    //     IOS;
    int T = 1;
    // cin >> T;
    scanf("%lld", &T);
    while (T--)
        solve();
    return 0;
}

 牛客网-该题目为付费比赛题目,请购买后查看

#include <bits/stdc++.h>
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define lowbit(x) (x & (-x))
#define int long long

typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<int, double> PID;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;
int n, k;
string s;

void solve()
{
    cin >> n >> k;
    cin >> s;
    vector<int> vec;
    int cnt = 0;
    int maxn = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] != '0')
        {
            maxn = max(maxn, cnt);
            if (cnt)
                vec.push_back(cnt);
            cnt = 0;
        }
        else
            cnt++;
    }
    if (cnt)
        vec.push_back(cnt);
    maxn = max(maxn, cnt);

    if (s[0] == s.back() && s[0] == '0')
    {
        vec[0] += vec.back();
        vec.pop_back();
        maxn = max(maxn, vec[0]);
    }

    // for (auto it : vec)
        // cout << it << ' ';

    int ans = 0;
    for (auto it : vec)
    {
        if (it == maxn)
        {
            ans += max(0ll, it - (1 + k));
            maxn = -1;
        }
        else
            ans += max(0ll, it - 2 * k);
    }
    cout << ans << '\n';
}

signed main()
{
    IOS;
    int T = 1;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

https://codeforces.com/contest/2126/problem/A 

 

#include<bits/stdc++.h>
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lowbit(x) (x & (-x))
#define int long long

typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<int, double> PID;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;

void solve()
{
    int a;
    cin >> a;
    int mn = 100;
    while(a)
    {
        mn = min(mn, a % 10);
        a /= 10;
    }
    cout << mn << '\n';
}

signed main()
{
    IOS;
    int T = 1;
    cin >> T;
    while(T --)
        solve();
    return 0;
}

https://codeforces.com/contest/2126/problem/B 

#include<bits/stdc++.h>
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lowbit(x) (x & (-x))
#define int long long

typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<int, double> PID;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;
int n, k;
int a[N];

void solve()
{
    cin >> n >> k;
    int ans = 0;
    for(int i = 1; i <= n; i++) cin >> a[i];
    vector<int> vec;
    int cnt = 0;
    for(int i = 1; i <= n; i++)
    {
        if(a[i] == 1)
        {
            if(cnt != 0) vec.push_back(cnt);
            cnt = 0;
        }
        else
            cnt++;
    }
    if(cnt)
        vec.push_back(cnt);
    for(auto it : vec)
        if(it == k) ans++;
        else
        {
            int m = it / (k + 1);
            int p = it - m * (k + 1);
            ans += m;
            if(p == k)
                ans++;
        }
    cout << ans << '\n';
}


signed main()
{
    IOS;
    int T = 1;
    cin >> T;
    while(T --)
        solve();
    return 0;
}

https://codeforces.com/contest/2126/problem/C

#include <bits/stdc++.h>
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define lowbit(x) (x & (-x))
#define int long long

typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<int, double> PID;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;
int n, k;

void solve()
{
    vector<int> vec;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        int a;
        cin >> a;
        vec.push_back(a);
    }
    k = vec[k - 1];
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    int st;
    for (st = 0; st < n; st++)
        if (vec[st] == k)
            break;
    int en = vec.back();
    // cout << st << ' ';

    int h = 1;
    for(int i = st + 1; i < n; i++)
    {
        int t1 = vec[i] - vec[i - 1];
        int t2 = vec[i - 1] + 1 - h;
        if(t1 > t2)
        {
            cout << "NO" << '\n';
            return;
        }
        h += t1;
    }
    cout << "YES" << '\n';
}

signed main()
{
    IOS;
    int T = 1;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

https://codeforces.com/contest/2126/problem/D

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

const int N = 2e5 + 10;

struct POI
{
    int l, r, val;
};

int n, k;
POI a[N];

bool cmp(const POI &A, const POI &B)
{
    return A.l < B.l;
}

void solve()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i].l >> a[i].r >> a[i].val;

    sort(a + 1, a + 1 + n, cmp);

    int cur = k, idx = 1;
    priority_queue<int> pq;

    while (true)
    {
        while (idx <= n && a[idx].l <= cur)
        {
            if (a[idx].r >= cur)
                pq.push(a[idx].val);
            idx++;
        }

        if (pq.empty())
            break;

        cur = max(cur, pq.top());
        pq.pop();
    }

    cout << cur << '\n';
}

signed main()
{
    IOS;
    int T;
    cin >> T;
    while (T--)
        solve();
    return 0;
}


网站公告

今日签到

点亮在社区的每一天
去签到