2024.5.15晚训题解

毫无难度啊。

A - Trick Taking

硬模拟就行。

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, t, c[maxn], r[maxn];
signed main(){
    cin >> n >> t;
    bool flag = 0;
    for(int i = 1; i <= n; i++) {
        cin >> c[i];
        if(c[i] == t) flag = 1;
    }
    int maxx1 = 0, maxx2 = 0, pos1 = -1, pos2 = -1;
    for(int i = 1; i <= n; i++) {
        cin >> r[i];
        if(c[i] == t && maxx1 < r[i]) maxx1 = r[i], pos1 = i;
        if(c[i] == c[1] && maxx2 < r[i]) maxx2 = r[i], pos2 = i;
    }
    cout << (flag ? pos1 : pos2);
    return 0;
}

B - Same Map in the RPG World

数据范围很小,可以直接枚举(s, t)的所有组合,判断即可。

当然码力弱的人未必能写。

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int n, m;
char a[35][35], b[35][35];
bool check(int s, int t) {
    bool flag = 1;
    for(int i = 1, j = s; i <= n; i++, j++) {
        if(j > n) j = 1;
        for(int k = t, h = 1; h <= m; k++, h++) {
            if(k > m) k = 1;
            if(a[i][h] != b[j][k]) {
                flag = 0;
                break;
            }
        }
        if(!flag) break;
    }
    return flag;
}
signed main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> a[i][j];
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> b[i][j];
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            if(check(i, j)) {
                cout << "Yes";
                return 0;
            }
    cout << "No";
    return 0;
}

C - Cross

直接枚举各个长度的十字架就完事了。

这场看起来相当暴力。

cpp 复制代码
# include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
char c[maxn][maxn];
int n, m, ans[maxn];
int d[][2] = {{-1, -1}, {-1, 1}, {1,  1}, {1,  -1}};
int check(int x, int y) {
    int ret = 0, t = 1;
    while(1) {
        for(int i = 0; i < 4; i++) {
            int dx = x + d[i][0] * t, dy = y + d[i][1] * t;
            if(dx < 1 || dx > n || dy < 1 || dy > m) return ret;
            if(c[dx][dy] == '.') return ret;
        }
        ret = t;
        t++;
    }
}
signed main() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> c[i][j];
    for(int i = 1; i <= n; i++)
        for(int j = 0; j < m; j++)
            if(c[i][j] == '#')
                ans[check(i, j)]++;
    for(int i = 1; i <= min(n, m); i++) cout << ans[i] << " ";
    return 0;
}

D - Cards Query Problem

典型的STL题:

对于操作1和操作2,我们可以开个vector数组,那么把数组 i i i 放入 j j j 实际上就可以用vj.push_back(i)来搞定,输出同理,排个序就完事了。

对于操作3来说有排序和去重操作,所以我们可以用set维护。

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, m;
vector<int> v[maxn];
set<int> s[maxn];
int main() {
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int opt, x; cin >> opt >> x;
        if(opt == 1) {
            int y; cin >> y;
            v[y].push_back(x), s[x].insert(y);
        } 
        else if(opt == 2) {
            sort(v[x].begin(), v[x].end());
            for(auto val : v[x]) cout << val << " ";
            cout << endl;
        } 
        else {
            for(auto val : s[x]) cout << val << " ";
            cout << endl;
        }
    }
    return 0;
}

E - Coloring Matrix

转4次不就完事了。跟温州市赛那题毫无区别,这题甚至还给了旋转公式,代码就不放了。

相关推荐
Jerry5 小时前
LeetCode 1002. 查找共用字符
算法
无限的鲜花6 小时前
协程本质是函数加状态机——零基础深入浅出 C++20 协程
c++·算法·c++20
旖-旎6 小时前
《LeetCode 64 最小路径和 || LeetCode 174 地下城游戏》
c++·算法·leetcode·动态规划
森林古猿16 小时前
再论斜率优化
c++·学习·算法
万法若空6 小时前
【数学-简单数论】同余中的逆
线性代数·算法
凯瑟琳.奥古斯特7 小时前
力扣1009补码解法C++实现
开发语言·c++·算法·leetcode·职场和发展
KaMeidebaby7 小时前
卡梅德生物技术快报|蛋白的叠氮基修饰:实操解析:核酸模板耦合蛋白的叠氮基修饰实现靶蛋白定点共价标记
前端·人工智能·物联网·算法·百度
通信仿真爱好者9 小时前
第【60期】--大规模MIMO系统信号检测算法误码率比较 --matlab完整代码+参考文章
算法·matlab·mimo·信号检测
AI科技星9 小时前
全域谱分析:无穷维超复数信息场分形统一场论——自然、量子、金融多重分形第一性原理完整体系(中英双语终稿)
人工智能·python·算法·金融·乖乖数学·全域数学
先吃饱再说10 小时前
为什么堆能 O(log n) 插入?拆解完全二叉树的数组魔法
算法·排序算法