Codeforces 321A Ciel and Robot 枚举答案

题目链接

枚举机器人走的最后一步,用终点坐差后计算周期次数

trick:周期次数要>=0

#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <cstdio>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
using namespace std;
template <class T>
inline bool rd(T &ret) {
    char c; int sgn;
    if (c = getchar(), c == EOF) return 0;
    while (c != '-' && (c<'0' || c>'9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}
template <class T>
inline void pt(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) pt(x / 10);
    putchar(x % 10 + '0');
}
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1e9;
const int N = 105;

ll a, b;
char s[N];
ll x[N], y[N];
int n;
bool work() {
    for (int i = 0; i < n; i++)
    {
        ll l = a - x[i];
        ll r = b - y[i];
        if (x[n] == 0)
        {
            if (l)continue;
            if (y[n] == 0)
            {
                if (r)continue;
                else return true;
            }
            if (r%y[n])continue;
            if(r/y[n] >= 0)
            return true;
            else continue;
        }
        if (l%x[n])continue;
        if (l / x[n] < 0)continue;
        if (y[n] == 0)
        {
            if (r)continue;
        
            return true;
        }
        if (r%y[n])continue;
        if (l / x[n] == r / y[n]) {
            if (l / x[n] >= 0)return true;
        }
    }
    return false;
}
int main() {
    rd(a); rd(b);
    scanf("%s", s + 1); n = strlen(s + 1);
    x[0] = y[0] = 0;
    for (int i = 1; s[i]; i++) {
        x[i] = x[i - 1]; y[i] = y[i - 1];
        if (s[i] == 'U')y[i] = y[i - 1] + 1;
        if (s[i] == 'D')y[i] = y[i - 1] - 1;
        if (s[i] == 'L')x[i] = x[i - 1] - 1;
        if (s[i] == 'R')x[i] = x[i - 1] + 1;
    }
    work() ? puts("Yes") : puts("No");
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值