AcWing - 5054. 拼接字符串+5055. 画矩形 -字符串+思维

5054. 拼接字符串

A,B,C一共有6中拼接,全部存储到一个数组里

然后针对每个查询,遍历数组中的每个拼接的字符串。

在上面这个过程中注意需要转换大小写,并且忽略非字母的符号

cpp 复制代码
#include <stdio.h>
#include <cstring>
#include <iostream>
using namespace std;
#define ll long long
#define sf(x) scanf("%d", &x);
#define de(x) cout << x << " ";
#define Pu puts("");
const int N = 2e4 + 9; 
string a, b, c;
string u[7];
string fun(string x) {
    string res = "";
    for (int i = 0; i < x.size(); i++) {
        if (x[i] >= 'a' && x[i] <= 'z')
            res += x[i];
        else if (x[i] >= 'A' && x[i] <= 'Z')
            res += (x[i] + 32);
    }
    return res;
}
int n;
int main() {
    cin >> a >> b >> c;
    a = fun(a);
    b = fun(b);
    c = fun(c);
    for (int i = 0; i < 6; i++) {
        u[i] = "";
    }
    u[0] = a + b + c;
    u[1] = a + c + b;
    u[2] = b + a + c;
    u[3] = b + c + a;
    u[4] = c + a + b;
    u[5] = c + b + a;
    cin >> n;
    string t;
    int flag;
    while (n--) {
        cin >> t;
        t = fun(t);
        flag = 0;
        for (int i = 0; i < 6; i++) {
            if (u[i] == t) {
                flag = 1;
                break;
            }
        }
        cout << ((flag == 1) ? "ACC\n" : "WA\n");
    }

    return 0;
}

5055. 画矩形

这个题目参考的题解:

其实是从n-1条线中选2k条,从m-1条线中选2 k条

因为我们每次画一个举行,需要2条横边+2条竖边

这样对于我们选出来的(2*k)^2条边中,其实是从外往里画矩形

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sf(x) scanf("%d", &x);
#define de(x) cout << x << " ";
#define Pu puts("");
const int N = 1e3 + 9, mod = 1e9 + 7;
int n, m;
int c[N][N];
int main() {
    int k;
    cin >> n >> m >> k;
    for (int i = 0; i <= 1e3; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0)
                c[i][j] = 1;
            else
                c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
        }
    }
    if (2 * k > n - 1 || 2 * k > m - 1)
        cout << "0\n";
    else
        cout << ((ll)c[n - 1][2 * k] * (ll)c[m - 1][2 * k]) % mod;
    // 注意这里需要进行强制转换,要不然1000,1000,250这个样例过不了
    return 0;
}
相关推荐
aaaameliaaa20 小时前
字符函数和字符串函数
c语言·笔记·算法
城管不管21 小时前
ReAct、Plan-and-Execute、Reflection 三大智能 Agent 范式核心区别
java·人工智能·算法·spring·ai·动态规划
月疯21 小时前
二分法算法(水平等分图形面积)
算法
豆瓣鸡21 小时前
算法日记 - Day3
java·开发语言·算法
白白白小纯1 天前
算法篇—反转链表
c语言·数据结构·算法·leetcode
Achou.Wang1 天前
深入理解go语言-第5章 并发编程——Go的灵魂
大数据·算法·golang
The Chosen One9851 天前
高进度算法模板速记(待完善)
java·前端·算法
土豆.exe1 天前
Fastjson2 2.0.53 哈希碰撞 RCE:从原理到三种打法
算法·哈希算法
黄河123长江1 天前
有限Abel群的结构()
算法
Jerry1 天前
LeetCode 92. 反转链表 II
算法