首页 > 其他分享 >The 18th Heilongjiang Provincial Collegiate Programming Contest

The 18th Heilongjiang Provincial Collegiate Programming Contest

时间:2023-09-05 13:33:28浏览次数:38  
标签:std Provincial const Contest int Programming cin Info using

链接:https://codeforces.com/gym/104363

A. Magic Computer

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

constexpr int P = 998244353;

i64 power(i64 a, i64 b) {
    i64 res = 1;
    for (; b; b >>= 1, a = a * a % P) {
        if (b & 1) {
            res = res * a % P;
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    cout << power(2, n - 1) << '\n';

    return 0;
}

B. Chevonne's Game

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

template<class Info, class Tag>
struct LazySegmentTree {
    int n;
    std::vector<Info> info;
    std::vector<Tag> tag;
    LazySegmentTree() : n(0) {}
    LazySegmentTree(int n_, Info v_ = Info()) {
        init(n_, v_);
    }
    template<class T>
    LazySegmentTree(std::vector<T> init_) {
        init(init_);
    }
    void init(int n_, Info v_ = Info()) {
        init(std::vector(n_, v_));
    }
    template<class T>
    void init(std::vector<T> init_) {
        n = init_.size();
        info.assign(4 << std::__lg(n), Info());
        tag.assign(4 << std::__lg(n), Tag());
        std::function<void(int, int, int)> build = [&](int p, int l, int r) {
            if (r - l == 1) {
                info[p] = init_[l];
                return;
            }
            int m = (l + r) / 2;
            build(2 * p, l, m);
            build(2 * p + 1, m, r);
            pull(p);
        };
        build(1, 0, n);
    }
    void pull(int p) {
        info[p] = info[2 * p] + info[2 * p + 1];
    }
    void apply(int p, const Tag &v) {
        info[p].apply(v);
        tag[p].apply(v);
    }
    void push(int p) {
        apply(2 * p, tag[p]);
        apply(2 * p + 1, tag[p]);
        tag[p] = Tag();
    }
    void modify(int p, int l, int r, int x, const Info &v) {
        if (r - l == 1) {
            info[p] = v;
            return;
        }
        int m = (l + r) / 2;
        push(p);
        if (x < m) {
            modify(2 * p, l, m, x, v);
        } else {
            modify(2 * p + 1, m, r, x, v);
        }
        pull(p);
    }
    void modify(int p, const Info &v) {
        modify(1, 0, n, p, v);
    }
    Info rangeQuery(int p, int l, int r, int x, int y) {
        if (l >= y || r <= x) {
            return Info();
        }
        if (l >= x && r <= y) {
            return info[p];
        }
        int m = (l + r) / 2;
        push(p);
        return rangeQuery(2 * p, l, m, x, y) + rangeQuery(2 * p + 1, m, r, x, y);
    }
    Info rangeQuery(int l, int r) {
        return rangeQuery(1, 0, n, l, r);
    }
    void rangeApply(int p, int l, int r, int x, int y, const Tag &v) {
        if (l >= y || r <= x) {
            return;
        }
        if (l >= x && r <= y) {
            apply(p, v);
            return;
        }
        int m = (l + r) / 2;
        push(p);
        rangeApply(2 * p, l, m, x, y, v);
        rangeApply(2 * p + 1, m, r, x, y, v);
        pull(p);
    }
    void rangeApply(int l, int r, const Tag &v) {
        return rangeApply(1, 0, n, l, r, v);
    }
    template<class F>
    int findFirst(int p, int l, int r, int x, int y, F pred) {
        if (l >= y || r <= x || !pred(info[p])) {
            return -1;
        }
        if (r - l == 1) {
            return l;
        }
        int m = (l + r) / 2;
        push(p);
        int res = findFirst(2 * p, l, m, x, y, pred);
        if (res == -1) {
            res = findFirst(2 * p + 1, m, r, x, y, pred);
        }
        return res;
    }
    template<class F>
    int findFirst(int l, int r, F pred) {
        return findFirst(1, 0, n, l, r, pred);
    }
    template<class F>
    int findLast(int p, int l, int r, int x, int y, F pred) {
        if (l >= y || r <= x || !pred(info[p])) {
            return -1;
        }
        if (r - l == 1) {
            return l;
        }
        int m = (l + r) / 2;
        push(p);
        int res = findLast(2 * p + 1, m, r, x, y, pred);
        if (res == -1) {
            res = findLast(2 * p, l, m, x, y, pred);
        }
        return res;
    }
    template<class F>
    int findLast(int l, int r, F pred) {
        return findLast(1, 0, n, l, r, pred);
    }
};
 
struct Tag {
    int x;
    Tag(int x = 0) : x(x) {};
    void apply(const Tag &t) {
        x ^= t.x;
    }
};

struct Info {
    int c0, c1, l, r;
    Info(int c0 = 0, int c1 = 0, int l = -1E9, int r = -1E9) {
        this->c0 = c0;
        this->c1 = c1;
        this->l = l;
        this->r = r;
    }
    void apply(const Tag &t) {
        if (t.x) {
            swap(c0, c1);
            l ^= 1;
            r ^= 1;
        }
    }
};

Info operator+(const Info &a, const Info &b) {
    int c0 = a.c0 + b.c0;
    int c1 = a.c1 + b.c1;
    return Info(c0 + (a.r + b.l == 0), c1 + (a.r + b.l == 2), a.l, b.r);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, q;
    string s;
    cin >> n >> q >> s;
    
    vector<Info> a(n);
    for (int i = 0; i < n; i++) {
        a[i].l = a[i].r = s[i] - '0'; 
    }
    
    LazySegmentTree<Info, Tag> seg(a);
    for (int i = 0; i < q; i++) {
        char o;
        int l, r;
        cin >> o >> l >> r;
        l--;
        if (o == 'M') {
            seg.rangeApply(l, r, 1);
        } else {
            auto res = seg.rangeQuery(l, r);
            cout << max(res.c0, res.c1) + 1 << '\n';
        }
    }
    
    return 0;
}

E. Ethernet

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m;
    cin >> n >> m;

    cout << fixed << setprecision(12);

    if (n != m) {
        cout << 1.0 / (m + 1) << '\n';
    } else {
        cout << 1.0 / n << '\n';
    }

    return 0;
}

F. Folder

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    set<int> s;
    for (int i = 0; i < n - 1; i++) {
        int x;
        cin >> x;
        s.insert(x);
    }
    cout << n - 1 - s.size() << '\n';

    return 0;
}

G. Gravity

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

using Real = i64;
using Point = complex<Real>;

Real cross(const Point &a, const Point &b) {
    return (conj(a) * b).imag();
}

Real dot(const Point &a, const Point &b) {
    return (conj(a) * b).real();
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vector<Point> a(n);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;

        a[i] = Point(x, y);
    }

    Point p(0, 0);
    for (int i = 0; i < n; i++) {
        p += a[i];
    }

    vector<double> b(n);
    for (int i = 0; i < n; i++) {
        b[i] = cross(a[i], p);
    }

    sort(b.begin(), b.end(), greater());
    
    double ans = 0;
    i64 sum = 0;
    for (int i = 0; i < n - 1; i++) {
        sum += b[i];
        ans = max(ans, 1.0 * sum / (1LL * (i + 1) * (n - i - 1)));
    }
    cout << fixed << setprecision(12) << ans / 2.0 << '\n';

    return 0;
}

标签:std,Provincial,const,Contest,int,Programming,cin,Info,using
From: https://www.cnblogs.com/kiddingma/p/17679350.html

相关文章

  • The 10th Shandong Provincial Collegiate Programming Contest
    链接:https://codeforces.com/gym/104459A#include"bits/stdc++.h"usingnamespacestd;usingi64=longlong;stringS[]={"Monday","Tuesday","Wednesday","Thursday","Friday&q......
  • 【题解】AtCoder Beginner Contest 318(D - Ex)
    赛时过了A-G,Ex仿佛猜到了结论但是完全不懂多项式科技,就炸了。大家好像都秒了A,B,C就不写了。D.GeneralWeightedMaxMatching题目描述:给你一个加权无向完全图,图中有\(N\)个顶点,编号从\(1\)到\(N\)。连接顶点\(i\)和\(j\)的\((i<j)\)的权重为\(D_{i,j}\)。在......
  • AtCoder Beginner Contest 318
    A-FullMoonProblemStatementTakahashilikesfullmoons.Lettodaybeday\(1\).Thefirstdayonoraftertodayonwhichhecanseeafullmoonisday\(M\).Afterthat,hecanseeafullmoonevery\(P\)days,thatis,onday\(M+P\),day\(......
  • AtCoder Beginner Contest 201 E - Xor Distances
    E-XorDistances原题链接题意:设dist(i,j)即i到j之间路径的异或和,求树上所有两点之间dist(i,j)的和思路:dist(i,j)=dist(i,1)^dist(j,1)根据异或性质相同的部分会被消掉用bfs求得dist(i,1)优化两层i,j的枚举:通过遍历每个数的每一位1的个数cnt,以及0的个数n-cnt,从而在1^0=1......
  • AtCoder Beginner Contest 201 D - Game in Momotetsu World
    D-GameinMomotetsuWorld原题链接题意有一个H×W的方格,每个方格里写着'+'或'-'有一个初始在(1,1),(也就是左上角)的棋子,Takahashi和Aoki轮流向右或向下移动(Takahashi先手)。移动到写着'+'的方格上后,进行该步移动的玩家分数+1。否则该玩家分数−1,走到右下......
  • AtCoder Beginner Contest 317 D - President
    D-President原题链接题意:一共n轮,每一轮Xi>Yi(票数)时,X可以获得Zi张席位,反之亦然;最终席位总和多的就获胜;因此要使X获胜,求Y至少要给X多少个票思路:数据范围小,Z的和小于1e5可以用01背包的方法,前i轮中,X获得的席位不超过j的最小票数,再对X获胜情况中(X的席位>=m/2+1)取最小......
  • AtCoder Beginner Contest 317 C - Remembering the Days
    C-RememberingtheDays原题链接题意:每个点最多经过一次,求最长路思路:数据范围很小,深搜每个点能到其他点的所有路,取最大#include<bits/stdc++.h>usingnamespacestd;constintN=110;intg[N][N];intn,m;boolst[N];intw=0;intans=0;voiddfs(intu){ st[......
  • 【题解】Harbour.Space Scholarship Contest 2023-2024 D,E,F(CF1864)
    D.MatrixCascade题目描述:有一个大小为\(n\timesn\)的矩阵,由0和1组成。行的编号从上到下依次为\(1\)到\(n\),列的编号从左到右依次为\(1\)到\(n\)。第\(x\)行与第\(y\)列交叉处的单元格记为\((x,y)\)。水月想把矩阵的所有元素都变成0。她可以一步完成以下操作:选择任意......
  • AtCoder Beginner Contest 317
    A-Potions#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongintpower(intx,inty,intp){x%=p;intans=1;while(y){if(y&1)ans=ans*x%p;y>>=1,x=x*x%p;}......
  • AtCoder Beginner Contest 292 E - Transitivity
    E-Transitivity原题链接题意:对于一个有向图,进行加边操作,使最终任意的个点具有传递效果,即若a到b有边,b到c有边,那么a到c也要有边,问最少需要进行多少次操作,使得每个节点所能到达的地方都有直接的边,也就是最短距离为1思路:怎么加边才是最优的,举个例子a->b->c->d->e对于a点到其他......