2024.5.15晚训题解

毫无难度啊。

A - Trick Taking
硬模拟就行。

#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)的所有组合,判断即可。
当然码力弱的人未必能写。

#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
直接枚举各个长度的十字架就完事了。
这场看起来相当暴力。

# 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 实际上就可以用v[j].push_back(i)来搞定,输出同理,排个序就完事了。
对于操作3来说有排序和去重操作,所以我们可以用set维护。

#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次不就完事了。跟温州市赛那题毫无区别,这题甚至还给了旋转公式,代码就不放了。

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值