acwing第 24 场周赛

题1题述

acwing第 24 场周赛

输入输出

acwing第 24 场周赛

数据范围、样例

acwing第 24 场周赛

代码

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;
int n,t=-100;
int a[N];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i],t=max(t,a[i]);
    int ans=t^a[n];
    cout<<ans;
}

题2题述

acwing第 24 场周赛
acwing第 24 场周赛

输入输出

acwing第 24 场周赛

数据范围、样例

acwing第 24 场周赛

代码

#include <bits/stdc++.h>
using namespace std;

const int N = 10;
string s1, s2;
int a[N][N];
int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

void dfs(int x, int y) {
    a[x][y] = 1;
    for (int i = 0; i < 8; i++) {
        int xx = dx[i] + x;
        int yy = dy[i] + y;
        if (xx < 1 || xx > 8 || yy < 1 || yy > 8 || a[xx][yy])  continue;
        a[xx][yy] = 1;
    }
}

int main() {
    cin >> s1 >> s2;
    int x = s1[0] - 'a' + 1, y = s1[1] - '0';
    int xx = s2[0] - 'a' + 1, yy = s2[1] - '0';
    dfs(xx, yy);
    int cnt = 0;
    for (int i = 1; i <= 8; i++)
        for (int j = 1; j <= 8; j++) {
            if (i == x || j == y || a[i][j])   continue;
            bool flag = true;
            for (int k = 0; k < 8; k++) {
                int tx = i + dx[k];
                int ty = j + dy[k];
                if (tx == x && ty == y) {
                    flag = false;
                    break;
                }
                if (tx == xx && ty == yy) {
                    flag = false;
                    break;
                }
            }
            if (flag)   cnt++;
        }
    cout << cnt << endl;
    return 0;
}


上一篇:567. 字符串的排列(中等,双指针,滑动窗口)


下一篇:【完虐算法】字符串-旋转词 复盘总结