zoukankan      html  css  js  c++  java
  • CHFDORA:哆啦 A 梦

    There are n cards of different colours placed in a line, each of them can be either red, green or blue cards. Count the minimum number of cards to withdraw from the line so that no two adjacent cards have the same colour.

    Input

    • The first line of each input contains an integer n— the total number of cards.
    • The next line of the input contains a string s, which represents the colours of the cards. We'll consider the cards in a line numbered from 1 to n from left to right. Then the itithh alphabet equals "G", if the itithh card is green, "R" if the card is red, and "B", if it's blue.

    Output

    • Print a single integer — the answer to the problem.

    Constraints

    • 1n501≤n≤50

    Sample Input 1:

    5
    RGGBG

    Sample Input 2:

    5
    RRRRR

    Sample Input 3:

    2
    BB

    ###Sample Output 1:
    1
    ###Sample Output 2:
    4
    ###Sample Output 3:
    1

    题目描述 哆啦 A 梦有一个 N 行 M 列的矩阵,行从 1 到 N 编号,列从 1 到 M 编号。令 Ai,j 为第 i 行 第 j 列的元素。接下来,定义第 r 行的一个子行为序列 Ar,x, Ar,x+1, . . . , Ar,y,其中 1 ≤ x ≤ y ≤ M, 同样地定义第 c 列的一个子列为序列 Ax,c, Ax+1,c, . . . , Ay,c,其中 1 ≤ x ≤ y ≤ N。 你需要求出满足以下条件的有序对(某一行的子行,某一列的子列)的个数:

    • 这两个序列(子行和子列)的长度相同。

    • 这个长度是奇数。

    • 这两个序列的中间元素相同(它们是矩阵中的同一个元素)。

    • 两个序列都是回文序列。

    输入格式

    • 输入的第一行是一个整数 T, 表示数据组数。接下来是 T 组数据。

    • 每组数据的第一行包含两个整数 N, M,用空格隔开。

    • 接下来 N 行。对每个 1 ≤ i ≤ N,第 i 行包含 M 个整数 Ai,1, Ai,2, . . . , Ai,m,用空格隔开。

    输出格式

    对于每组数据输出一行一个整数——合法的有序对的个数

    输入

    1 3 3 2 1 2 1 1 1 2 1 2

    输出 10

    //#include<bits/stdc++.h>
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<map>
    #include<set>
    #include<vector>
    #include<iomanip>
    using namespace std;
    typedef long long ll;
    const ll inf = 0x3f3f3f3f;
    const ll mod = 1e9+7;
    const double eps = 1e-8;
    const ll mx = 1e6+10; //check the limits, dummy
    typedef pair<int, int> pa;
    const double PI = acos(-1);
    ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
    ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
    bool isprime(int n) { if (n <= 1)return 0; for (int i = 2; i * i <= n; i++)if (n % i == 0)return 0; return 1; }
    #define swa(a,b) a^=b^=a^=b
    #define re(i,a,b) for(int i=(a),_=(b);i<_;i++)
    #define rb(i,a,b) for(ll i=(a),_=(b);i>=_;i--)
    #define clr(a,b) memset(a, b, sizeof(a))
    #define lowbit(x) ((x)&(x-1))
    #define mkp make_pair
    inline ll qpow(ll a, ll b) { return b ? ((b & 1) ? a * qpow(a * a % mod, b >> 1) % mod : qpow(a * a % mod, b >> 1)) % mod : 1; }
    inline ll qpow(ll a, ll b, ll c) { return b ? ((b & 1) ? a * qpow(a * a % c, b >> 1) % c : qpow(a * a % c, b >> 1)) % c : 1; }
    void ca(int kase, int ans) { cout << "Case #" << kase << ": " << ans << endl; }
    //void sc(int& x) { scanf("%d", &x); }void sc(int64_t& x) { scanf("%lld", &x); }void sc(double& x) { scanf("%lf", &x); }void sc(char& x) { scanf(" %c", &x); }void sc(char* x) { scanf("%s", x); }
    ll t,m,n,k;
    ll ans=0;
    ll sum = 0,b[mx];
    string s;
    ll cnt = 0;
    int main()
    {
        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        cin >> t;
        while (t--) {
            cin >> n>>m;
            vector<vector<ll>>a(n, vector <ll>(m, 0));//key step
            re(i, 0, n)re(j, 0, m)cin >> a[i][j];
            ans = 0;
            re(i, 0, n) {
                re(j, 0, m) {
                    cnt = 0;
                    ll x1 = i, x2 = i, y11 = j, y2 = j;
                    while (x1 >= 0 && x2 < n && y11 >= 0 && y2 < m && a[x1][j] == a[x2][j] && a[i][y11] == a[i][y2]) {
                        x1--, x2++, y11--, y2++, cnt++;
                    }
                    ans += cnt;
                }
            }
            cout << ans << endl;
        }
        return 0;
    }
  • 相关阅读:
    获取网络时间,减轻自己服务器的请求压力
    mysql学习记录(windows)
    Docker 部署本地pip源
    npm : 无法加载文件 D:vueProject odejs ode_global pm.ps1
    微信小程序没有找到可构建的npm包
    vue 记录 mode:history 模式 踩过的坑
    Linux学习笔记
    kafka监控 Kafka-eagle-web
    vi 分屏 --(visual 可视模式)
    [安卓网络入门] 获取天气
  • 原文地址:https://www.cnblogs.com/xxxsans/p/13160726.html
Copyright © 2011-2022 走看看