首页 > 其他 > 详细

HDU 7108 Command Sequence

时间:2021-09-01 14:52:58      阅读:9      评论:0      收藏:0      [点我收藏+]

题目链接:HDU 7108 Command Sequence

题目大意:
技术分享图片

题解:
记录所有经过的点,对重复的点计算组合数。

#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
#define LL long long

map<pair<LL, LL>, LL> mat;
LL t, n, x, y, ans;
char ch[100010];

int main() {
    scanf("%lld", &t);
    while (t--) {
        scanf("%lld", &n);
        scanf("%s", ch);
        x = y = ans = 0;
        mat.clear();
        mat[make_pair(0ll, 0ll)]++;
        for (int i = 0; i < n; ++i) {
            if (ch[i] == ‘U‘) y++;
            else if (ch[i] == ‘D‘) y--;
            else if (ch[i] == ‘L‘) x--;
            else x++;
            if (mat[make_pair(x, y)]) ans += mat[make_pair(x, y)];
            mat[make_pair(x, y)]++;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

HDU 7108 Command Sequence

原文:https://www.cnblogs.com/IzumiSagiri/p/15203259.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!