Codeforces 834 A The Useless Toy

本文介绍了一种简单的算法,用于根据起点和终点字符以及步数来判断行走的方向是顺时针、逆时针还是两者皆可。该算法通过计算起点字符的位置,并在给定步数的基础上分别尝试顺时针和逆时针移动,最终确定移动的方向。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目地址
题意:你有一个序列如下图,给你起点和终点的字符以及经过步数n,请你判断是顺时针还是逆时针还是都可以
v,<,^,>
思路:求出起点的位置,从这个位置开始逆时针和顺时针都走n%4的步数,然后比较这两种情况得到的点是终点,如果两个都是终点就是都可以
PS:那个v是小写,这个错误找了我好久

#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define N 100010
#define LL long long
#define inf 0x3f3f3f3f
#define lson l,mid,ans<<1
#define rson mid+1,r,ans<<1|1
using namespace std;
const LL mod = 1e9 + 7;
const double eps = 1e-9;
int main() {
    cin.sync_with_stdio(false);
    int n;
    char a, b;
    char num[4] = { 'v','<','^','>' };
    while (cin >> a >> b) {
        cin >> n;
        int aa, bb, cc;
        for (int i = 0; i < 4; i++) {
            if (num[i] == a) {
                cc = i;
            }
        }
        n %= 4;
        aa = (cc + n) % 4;
        bb = (cc - n + 4) % 4;
        if (num[aa] == b&&num[bb] == b) {
            cout << "undefined" << endl;
        }
        else if (num[aa] == b) {
            cout << "cw" << endl;
        }
        else {
            cout << "ccw" << endl;
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值