CHESSBOARD(模拟)

CHESSBOARD

题解

所有都遍历一遍,如此暴力居然没超时。

#include <string>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
#define ll long long
int n, m, o, l;
bool map[600][600];
char road[600];

int main() {
    int t;
    int cas = 0;
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d%d%d", &n, &m, &o, &l);
        memset(map, 1, sizeof(map));
        for (int i = 1; i <= o; i++) {
            int x, y;
            scanf("%d%d", &x, &y);
            map[x][y] = 0;
        }
        scanf("%s", road + 1);
        ll ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (map[i][j] != 0) {
                    int endI = i, endJ = j;
                    for (int k = 1; k <= l; k++) {
                        if (road[k] == 'U' && endI - 1 >= 1 && map[endI - 1][endJ]) {
                            endI -= 1;
                        } else if (road[k] == 'R' && endJ + 1 <= m && map[endI][endJ + 1]) {
                            endJ += 1;
                        } else if (road[k] == 'L' && endJ - 1 >= 1 && map[endI][endJ - 1]) {
                            endJ -= 1;
                        } else if (road[k] == 'D' && endI + 1 <= n && map[endI + 1][endJ]) {
                            endI += 1;
                        }
                    }
                    ans = ans + (ll) ((i - endI) * (i - endI) + (j - endJ) * (j - endJ));
                }
            }
        }
        printf("Case #%d: %lld\n", ++cas, ans);
    }

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值