首页 > 其他分享 >The 10th Shandong Provincial Collegiate Programming Contest

The 10th Shandong Provincial Collegiate Programming Contest

时间:2023-09-05 12:25:55浏览次数:39  
标签:std Provincial Shandong Contest int cin long ++ using

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

A

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

string S[] = {
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday"
};

void solve() {
    int y1, m1, d1;
    string s;
    cin >> y1 >> m1 >> d1 >> s;
    int i = 0;
    while (s != S[i]) {
        i++;
    }

    int y2, m2, d2;
    cin >> y2 >> m2 >> d2;

    i64 j = i + (y2 - y1) * 360LL +  (m2 - m1) * 30LL + (d2 - d1);
    j %= 5;
    j += 5;
    j %= 5;
    cout << S[j] << '\n'; 
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

C

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int x = 0, y = 0;
    vector<pair<int, int>> a(n);
    i64 ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'U') {
            y++;
        } else if (s[i] == 'D') {
            y--;
        } else if (s[i] == 'L') {
            x--;
        } else {
            x++;
        }
        a[i] = {x, y};
        ans = max(ans, 1LL * abs(x) + abs(y));
    }

    auto &[X, Y] = a[n - 1];
    for (int i = 0; i < n; i++) {
        auto &[x, y] = a[i];
        ans = max(ans, abs(1LL * (k - 1) * X + x) + abs(1LL * (k - 1) * Y + y));
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

D. Game on a Graph

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
    int k;
    string s;
    cin >> k >> s;
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
    }
    int cnt = m - (n - 1);
    
    cout << 3 - (s[cnt % k] - '0') << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

F. Stones in the Bucket

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    i64 sum = accumulate(a.begin(), a.end(), 0LL);
    
    i64 ave = sum / n;
    i64 ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > ave) {
            ans += a[i] - ave;
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

L. Median

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
    int n, m;
    cin >> n >> m;

    vector<vector<int>> g(n), rg(n);
    vector<int> deg(n), rdeg(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
        rg[v].push_back(u);
        deg[v]++;
        rdeg[u]++;
    }
    vector<bitset<101>> f(n), rf(n);
    auto bfs = [&](const vector<vector<int>> &g, vector<int> &deg,
                vector<bitset<101>> &f) {
        queue<int> q;
        for (int i = 0; i < n; i++) {
            if (!deg[i]) {
                q.push(i);
            }
        }
        int tot = 0;
        while (!q.empty()) {
            auto cur = q.front();
            q.pop();
            tot++;
            for (auto &nex : g[cur]) {
                if (!--deg[nex]) {
                    q.push(nex);
                }
                f[nex][cur] = 1;
                f[nex] |= f[cur];
            }
        }
        return tot;
    };

    int tot = bfs(g, deg, f);
    if (tot != n) {
        cout << string(n, '0') << '\n';
        return;
    }
    bfs(rg, rdeg, rf);
    int k = n / 2;
    for (int i = 0; i < n; i++) {
        int l = f[i].count();
        int r = rf[i].count();
        if (l <= k && r <= k) {
            cout << 1;
        } else {
            cout << 0;
        }
    }
    cout << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

M. Sekiro

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
    int n, k;
    cin >> n >> k;

    for (int i = 0; i < k; i++) {
        n = (n + 1) / 2;
        if (n == 0 || n == 1) {
            break;
        }
    }
    cout << n << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

标签:std,Provincial,Shandong,Contest,int,cin,long,++,using
From: https://www.cnblogs.com/kiddingma/p/17679262.html

相关文章

  • 【题解】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点到其他......
  • AtCoder Beginner Contest 292 D - Unicyclic Components
    D-UnicyclicComponents原题链接题意:判断一个连通块的边和点个数是否相同思路:对它使用并查集吧点击查看代码#include<bits/stdc++.h>usingnamespacestd;constintN=200010,M=N<<1;//维护连通图中点和边的个数intsd[N],se[N],p[N];boolf[N];//谁是祖宗int......