Codeforces 894 A B 组合数学 比赛

  题目链接: http://codeforces.com/contest/894

  A: QAQ

  题目描述: 问你一个字符串中有多少个QAQ

  解题思路: 简单暴力

  代码: 

#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main() {
    string str;
    cin >> str;
    int n = (int)str.length();
    long long res = 0;
    for(int i = 0; i < n; i++) {
        if(str[i] == 'A') {
            int cnt_f = 0, cnt_b = 0;
            for(int j = 0; j < i; j++) {
                if(str[j] == 'Q') cnt_f++;
            }
            for(int j = i+1; j < n; j++) {
                if(str[j] == 'Q') cnt_b++;
            }
            res += cnt_f * cnt_b;
        }
    }
    cout << res << endl;
    return 0;
}
View Code

  B: Ralph And His Magic Field

  题目描述: 有n行m列。拉尔夫可以在每个块中放置一个整数。然而,魔术领域并不总是正常工作。只有在每行和每列中的整数乘积等于k时才有效,其中k是1或-1。现在拉尔夫想让你弄清楚在每个区块中放置数字的方法数量,以使魔法区域正常工作。(那么只能放1 or -1)两种方式被认为是不同的,当且仅当至少存在一个块,其中第一种方式和第二种方式中的数字是不同的。你被要求输出答案%1e9+7。(描述转自https://www.cnblogs.com/Roni-i/p/7866373.html)

  解题思路: 我......我写了一张纸, 因为我觉得我要敲很久键盘才能表达清楚自己的意思......各位巨巨见谅......

   代码: 

: Codeforces Round #447 (Div. 2), problem: (B) Ralph And His Magic Field, Accepted, #
 #include <iostream>
#include <cstring>
#include <string>
using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
ll quick_power (ll a, ll b) {
    ll ret = 1;
    while(b) {
        if(b & 1) ret = ret * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ret % mod;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    if(n%2 != m%2 && k == -1) {
        cout << 0 << endl;
    }
    else {
        cout << quick_power(quick_power(2, n-1), m-1) << endl;
    }
    return 0;
}
View Code

  思考: 自己在比赛当中没有搞出来这道题, 特殊情况也没有讨论, 思路是正确的, 说这有啥用? 继续做C题

原文地址:https://www.cnblogs.com/FriskyPuppy/p/7899087.html