首页 > 其他分享 >Codeforces Round #828 (Div. 3) A~F

Codeforces Round #828 (Div. 3) A~F

时间:2022-11-17 22:45:54浏览次数:54  
标签:int ll Codeforces long cin -- while 828 Div

A

签到

点击查看代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
int n;
map<int, char> m;
int a[N];
char s[N];

int main() {
    int t;
    cin >> t;
    while(t--) {
        cin >> n;
        for(int i = 1; i <= n; i++) cin >> a[i], m[a[i]] = '0';
        scanf("%s", s + 1);
        // m.clear();
        bool f = 1;
        set<char> ss[55];
        for(int i = 1; i <= n; i++) {
            ss[a[i]].insert(s[i]);
            if(ss[a[i]].size() > 1) {
                f = 0;
                break;
            }
        }
        if(f) puts("YES");
        else puts("NO");
    }
    system("pause");
    return 0;
}

B

模拟即可。

点击查看代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 10;
int n, q;
int a[N];
int op, x;

int main() {
    int t;
    cin >> t;
    while(t--) {
        cin >> n >> q;
        int even = 0, odd = 0;
        ll s = 0;
        for(int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
            if(a[i] % 2) odd += 1;
            else even += 1;
            s += a[i];
        }
        int change = 0;
        while(q--) {
            scanf("%d%d", &op, &x);
            if(op == 0) {
                s += 1ll * x * even;
                printf("%lld\n", s);
                if(x % 2 == 1) {
                    even = 0;
                    odd = n;
                }
            }
            else {
                s += 1ll * x * odd;
                printf("%lld\n", s);
                if(x % 2 == 1) {
                    even = n;
                    odd = 0;
                }
            }
        }
    }
    system("pause");
    return 0;
}

C

模拟。

点击查看代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 4e5 + 10;
int n, q;
char s[N], now_c;
int ti[N];

int main() {
    int t;
    cin >> t;
    while(t--) {
        cin >> n; getchar(); scanf("%c", &now_c);
        scanf("%s", s + 1);
        for(int i = n + 1; i <= 2 * n; i++) s[i] = s[i - n];
        for(int i = 1; i <= 2 * n; i++) ti[i] = 1e9;
        int ans = 0;
        int mn_g = 1e9;
        for(int i = 2 * n; i >= 1; i--) {
            if(s[i] == 'g') {
                mn_g = i;
                ti[i] = 0;
            }
            else {
                if(mn_g == 1e9) continue;
                ti[i] = mn_g - i;
            }
            if(s[i] == now_c) ans = max(ans, ti[i]);
        }
        printf("%d\n", ans);
    }
    system("pause");
    return 0;
}

D

贪心。

点击查看代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
int n, q;
int a[N];
int cnt[42];
map<ll, int> f;

int main() {
    ll w = 1;
    int c = 0;
    while(w <= 1e9) {
        w *= 2;
        c++;
        f[w] = c;
    }

    int t;
    cin >> t;
    while(t--) {
        cin >> n;
        int tot = 0;
        for(int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
            tot += f[(a[i] & (-a[i]))];
        }
        int more = n - tot;
        if(more <= 0) {
            puts("0");
            continue;
        }
        for(int i = 0; i <= 30; i++) cnt[i] = 0;
        ll mx = 0; // 下标最多可以组成 2^mx
        for(int i = 2; i <= n; i += 2) {
            int k = (i & (-i));
            k = f[k];
            cnt[k] += 1;
            mx += k;
        }
        if(mx < more) puts("-1");
        else {
            int ans = 0;
            for(int i = 30; i >= 1; i--) {
                while(cnt[i] > 0 && more > 0) {
                    more -= i;
                    cnt[i]--;
                    ans++;
                }
                if(more <= 0) break;
            }
            printf("%d\n", ans);
        }
    }
    system("pause");
    return 0;
}

E1

直接当E2做的,wa了很多发。

枚举即可。

点击查看代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 10;
int n, q;
ll a, b, c, d;

bool inline check(ll x, ll y) {
    return (x > a && x <= c && y > b && y <= d);
}

int main() {
    int t; cin >> t;
    while(t--) {
        cin >> a >> b >> c >> d;
        bool f = 0;
        for(ll i = a + 1; i <= c; i++) {
            ll k = __gcd(a * b, i);
            k = (a * b) / k;
            ll k2 = d / k;
            if(k * k2 > b && k * k2 <= d) {
                f = 1;
                cout << i << ' ' << k2 * k << endl;
                break;
            }
        }
        if(f) continue;
        puts("-1 -1");
    }
    system("pause");
    return 0;
}

E2

分析可知,新得到的x和y必然包含a*b的所有因子,那么就按这个思路分即可。

怎么分?有OEIS可知一个1e9大小的数大约有1300+种不同的因子,枚举这些因子。

因为这两部分因子不一定位于给定区间范围内,再乘上系数放大一下即可。

点击查看代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 10;
int n, q;
ll a, b, c, d;

bool inline check(ll x, ll y) {
    return (x > a && x <= c && y > b && y <= d && x * y % (a * b) == 0);
}

int main() {
    int t; cin >> t;
    while(t--) {
        cin >> a >> b >> c >> d;
        bool f = 0;
        vector<int> va, vb;
        for(int i = 1; 1ll * i * i <= a; i++) {
            if(a % i == 0) {
                va.push_back(i);
                if(1ll * i * i != a) va.push_back(a / i);
            }
        }
        for(int i = 1; 1ll * i * i <= b; i++) {
            if(b % i == 0) {
                vb.push_back(i);
                if(1ll * i * i != b) vb.push_back(b / i);
            }
        }
        for(auto i : va) {
            if(f) break;
            for(auto j : vb) {
                ll x = 1ll * i * j, y = 1ll * a * b / i / j;
                x *= (a / x + 1);
                y *= (b / y + 1);
                if(x <= c && y <= d) {
                    f = 1;
                    cout << x << ' ' << y << endl;
                    break;
                }
            }
        }
        if(!f) puts("-1 -1");
    }
    system("pause");
    return 0;
}

F

思路就是按照mex递增的方式计算贡献。(先分析)

需要注意细节,细节见代码。

点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int n, q;
int a[N], pos[N];

signed main() {
    int t; cin >> t;
    while(t--) {
        cin >> n;
        for(int i = 1; i <= n; i++) {
            scanf("%lld", &a[i]);
            pos[a[i]] = i;
        }
        int L = pos[0], R = pos[0];
        int lcnt = L - 1, rcnt = n - R;
        int ans = 1;
        for(int len = 2; len <= n; len++) {
            if(len % 2) {
                L = min(L, pos[len / 2]);
                R = max(R, pos[len / 2]);
                lcnt = L - 1;
                rcnt = n - R;
            }
            int more = len - (R - L + 1);
            if(more < 0) continue;
            // 左边选 x 个,右边选 more - x 个
            int mx = min(lcnt, more), mn = more - rcnt;
            if(mx >= mn) ans += (mx - max(0ll, mn) + 1);
            // cout <<"mx:" << mx << " mn:" << mn << " add:" << (mx - max(0, mn) + 1) << " ans:" << ans<< endl;
        }
        printf("%lld\n", ans);
    }
    system("pause");
    return 0;
}

p.s.
第一次做出了div3所有题目!绿了耶( •̀ ω •́ )y

标签:int,ll,Codeforces,long,cin,--,while,828,Div
From: https://www.cnblogs.com/re0acm/p/16901294.html

相关文章

  • Codeforces 1646 D. Weight the Tree
    题意给你n个节点的树,让你给每个节点进行赋值,并且赋的值需要为正整数;同时当一个节点的值等于所有邻居节点的值的和时,这个点为好点;求出一组赋值情况,满足树的好点个数最大......
  • WEB安全DIV+CSS基础
    0x001DIV+CSS介绍层叠样式表(英文全称:CascadingStyleSheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机......
  • CodeForces - 372C Watching Fireworks is Fun
    题意:有n个点,其中m个要放烟花。每个放烟花的点有属性b[i],放的时间t[i]和位置a[i]。假设放烟花的时候你在位置x,那么可以获得快乐b[i]-|x-a[i]|。你走来走去地看烟花,起始位置......
  • Codeforces Round #833 (Div. 2)-B
    B题目链接:https://codeforces.com/contest/1748/problem/B Whatisthemaximumpossiblelengthadiversestring?100!10个数字每个出现10次暴力n*102下见代码#......
  • B. Diverse Substrings
    题目链接:Problem-B-Codeforces输入71727741010501100639999652345618789987887987998798输出1210121015106题目大意就是给出T个用例给出一个长度为n,只包含'0'......
  • Codeforces Gym 100958 E Cellular Automaton (Makoto rng_58 Soejima contest) 题解
    题目链接其实"序列中1的数量有限"是一个非常重要的条件。这意味着我们可以找到序列中的第一个1和最后一个1。考虑这样一件事情:初始时我们把一个长度为\(2^{2w+1}\)的"滑......
  • vue3点击其他元素隐藏固定DIV
    vue3点击其他元素隐藏固定DIV显示的内容<divv-if="hSearch"ref="iscity"><div><inputclass="h-9w-full"placeholder="内容搜索..."/></div></div>元......
  • Codeforces Round #833 (Div. 2) D
    D.ConstructOR转化题意a|x=k1db|x=k2d我们考虑k1k2同样就只用让x包含a|b对于a|b的每一位我们用d的最后一位来填补然后在线的要是a|b这里有我们的x没有显然要让......
  • CodeForces - 212E IT Restaurants
    题意:给一棵树的结点染色,每个结点可以染红色、蓝色或不染色。相邻两个结点必须染同一种颜色,或者一个染色一个不染色。求整棵树染色结点最多,且在整棵树至少有一个结点染红色,......
  • From CodeForces Catlogs
    2022/11/1https://codeforces.com/blog/entry/106346On"isthisgreedyorDP",forcingandrubberbandsreadingotherpeople'sthoughtprocessesTheylookatth......