zoukankan      html  css  js  c++  java
  • Testing Beta Round (Unrated)

    比赛链接:https://codeforces.com/contest/1390

    A. 123-sequence

    题意

    给出一个只含有 $1,2,3$ 的数组,问使所有元素相同至少要替换多少元素。

    题解

    统计数组中出现次数最多的元素即可。

    代码

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        int n; cin >> n;
        int mx = 0;
        map<int, int> cnt;
        for (int i = 0; i < n; ++i) {
            int x; cin >> x;
            mx = max(mx, ++cnt[x]);
        }
        cout << n - mx << "
    ";
    }

    B. Right Triangles

    题意

    给出一个只含有 '*','.' 的 $n imes m$ 的方阵,问方阵中有多少两条直角边与方阵平行的由 '*' 组成三个顶点的直角三角形。

    题解

    预处理出每个点上下左右 '*' 的个数,然后枚举四个方向的直角三角形即可。

    Tips

     == 的优先级要先于 = ,所以如果赋值中有 == ,应将其括起来。

    代码

    #include <bits/stdc++.h>
    using ll = long long;
    using namespace std;
    const int N = 1005;
    
    int n, m;
    char MP[N][N];
    ll u[N][N], d[N][N], l[N][N], r[N][N];
    
    int main() {
        cin >> n >> m;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= m; ++j) {
                cin >> MP[i][j];
            }
        }
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= m; ++j) {
                l[i][j] = l[i][j - 1] + (MP[i][j] == '*');
            }
            for (int j = m; j >= 1; --j) {
                r[i][j] = r[i][j + 1] + (MP[i][j] == '*');
            }
        }
        for (int i = 1; i <= m; ++i) {
            for (int j = 1; j <= n; ++j) {
                u[j][i] = u[j - 1][i] + (MP[j][i] == '*');
            }
            for (int j = n; j >= 1; --j) {
                d[j][i] = d[j + 1][i] + (MP[j][i] == '*');
            }
        }
        ll ans = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= m; ++j) {
                if (MP[i][j] == '*') {
                    --u[i][j], --d[i][j], --l[i][j], --r[i][j]; //减去自身
                    ans += u[i][j] * l[i][j];
                    ans += u[i][j] * r[i][j];
                    ans += d[i][j] * l[i][j];
                    ans += d[i][j] * r[i][j];
                }
            }
        }
        cout << ans << "
    ";
    }

    今晚的 cf 明天再补,早些休息吧

  • 相关阅读:
    ZH奶酪:PHP 使用DOMDocument抓取网页
    PHP Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity,
    ZH奶酪:PHP 执行时间Fatal error: Maximum execution time of...
    ZH奶酪:PHP (爬虫)下载图片
    ZH奶酪:PHP的cURL库
    PHP 字符串编码的转换
    PHP http_build_query()方法
    ZH奶酪:使用PHP调用REST API
    PHP全局变量
    HTML页面跳转的5种方式
  • 原文地址:https://www.cnblogs.com/Kanoon/p/13374153.html
Copyright © 2011-2022 走看看