o1-mini-2024-09-12· OpenAI
WildChat-4.8M (AI2)
B. 爱丽丝国际象棋历险记 time limit per test: 1 seconds memory limit per test: 256 megabytes input:…
- User
B. 爱丽丝国际象棋历险记
time limit per test: 1 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output
题目描述
爱丽丝正试图在郊外与红皇后会合!现在,爱丽丝在位置 ,红皇后在位置 。爱丽丝只能向四个基本方向(北、东、南、西)移动。
更正式地说,如果爱丽丝在点 ,她会做以下其中一个动作:
- 向北(用 N 表示),移动到 ;
- Assistantcpp
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while(t--){ int n, a, b; cin >> n >> a >> b; string s; cin >> s; // Initialize position int x = 0, y = 0; bool found = false; // Set step limit, e.g., 1000 int step_limit = 1000; for(int step=0; step < step_limit; step++){ // Determine current move char move = s[step % n]; // Apply move if(move == 'N') y +=1; else if(move == 'S') y -=1; else if(move == 'E') x +=1; else if(move == 'W') x -=1; // Check position if(x == a && y == b){ found = true; break; } } if(found){ cout << "YES\n"; } else{ cout << "NO\n"; } } }