首页 > 其他分享 >The 2022 ICPC Asia Nanjing Regional Contest

The 2022 ICPC Asia Nanjing Regional Contest

时间:2023-09-05 13:59:21浏览次数:42  
标签:Contest int Regional Nanjing else ++ Point using --

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

A. Stop, Yesterday Please No More

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    string s;
    cin >> s;
    int len = s.size();
    int u = 1, d = n, l = 1, r = m;
    int mnx = 1, mxx = n, mny = 1, mxy = m;
    for (int i = 0; i < len; i++) {
        if (s[i] == 'U') {
            u++;
            d++;
        } else if (s[i] == 'D') {
            u--;
            d--;
        } else if (s[i] == 'L') {
            l++;
            r++;
        } else {
            l--;
            r--;
        }

        mnx = max(mnx, u);
        mxx = min(mxx, d);
        mny = max(mny, l);
        mxy = min(mxy, r);
    }

    if (mnx > mxx || mny > mxy) {
        if (k == 0) {
        cout << n * m << '\n';
        return;
        }
        cout << 0 << '\n';
        return;
    }

    int res = (mxx - mnx + 1) * (mxy - mny + 1) - k;
    vector<vector<i64>> pre(2 * n + 1, vector<i64>(2 * m + 1));
    int x = n + 1, y = m + 1;
    pre[x][y] = 1;
    for (int i = 0; i < len; i++) {
        if (s[i] == 'U') {
            x++;
        } else if (s[i] == 'D') {
            x--;
        } else if (s[i] == 'L') {
            y++;
        } else {
            y--;
        }
        pre[x][y] = 1;
    }

    for (int i = 1; i <= 2 * n; i++) {
        for (int j = 1; j <= 2 * m; j++) {
            pre[i][j] += pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1];
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int U = mnx - i + n + 1;
            int D = mxx - i + n + 1;
            int L = mny - j + m + 1;
            int R = mxy - j + m + 1;
            if (pre[D][R] - pre[U - 1][R] - pre[D][L - 1] + pre[U - 1][L - 1] == res) {
                ans++;
            }
        }
    }
    cout << ans << '\n';
}

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

G. Inscryption

#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];
    }
    int cnt = 0;
    int ans1 = 1, ans2 = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) {
            ans1++;
            ans2++;
        } else if (a[i] == -1) {
            if (ans2 >= 2) {
                ans2--;
            } else if (cnt >= 1) {
                cnt--;
                ans1++;
                ans2++;
            } else {
                cout << -1 << '\n';
                return;
            }
            } else {
            if (ans2 >= 2) {
                ans2--;
                cnt++;
            } else {
                ans1++;
                ans2++;
            }
        }
    }
    int g = gcd(ans1, ans2);
    cout << ans1 / g << ' ' << ans2 / g << '\n';
}

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

I. Perfect Palindrome

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
    string s;
    cin >> s;
    vector<int> cnt(26);
    for (int i = 0; i < (int) s.size(); i++) {
        cnt[s[i] - 'a']++;
    }
    int ans = s.size();
    for (int i = 0; i < 26; i++) {
        ans = min(ans, (int) s.size() - cnt[i]);
    }
    cout << ans << '\n';
}

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

M. Drain the Water Tank

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

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

#define x real
#define y imag

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();
}

struct Line {
    Point a, b;
    Line() = default;
    Line(const Point &a, const Point &b) : a(a), b(b) {}
};

int onLeft(const Point &p, const Line &l) {
    return cross(l.b - l.a, p - l.a);
}

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);
    }

    int ans = 0;
    for (int i = 0, j = 1; i < n; i++) {
        while (a[i].y() == a[j].y()) {
            j++;
            j %= n;
        }
        if (a[i].y() < a[(i + n - 1) % n].y() && a[i].y() < a[j].y()) {
            if (a[i].y() != a[(i + 1) % n].y()) {
                if (onLeft(a[(i + n - 1) % n], Line(a[i], a[j])) > 0) {
                    ans++;
                }
            } else {
                if (a[i].x() < a[(i + 1) % n].x()) {
                    ans++;
                }
            }
        }
    }

    cout << ans << '\n';
    
    return 0;
}

标签:Contest,int,Regional,Nanjing,else,++,Point,using,--
From: https://www.cnblogs.com/kiddingma/p/17679360.html

相关文章

  • The 2022 ICPC Asia Hangzhou Regional Programming Contest
    The2022ICPCAsiaHangzhouRegionalProgrammingContestNoBugNoGame  #include<bits/stdc++.h>usingnamespacestd;#defineendl"\n"#defineintlonglongtypedeflonglongll;constintN=3e3+10;intf[N][N][2];signedm......
  • The 18th Heilongjiang Provincial Collegiate Programming Contest
    链接:https://codeforces.com/gym/104363A.MagicComputer#include"bits/stdc++.h"usingnamespacestd;usingi64=longlong;constexprintP=998244353;i64power(i64a,i64b){i64res=1;for(;b;b>>=1,a=a*a%P){......
  • 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。她可以一步完成以下操作:选择任意......