文章
219
粉丝
165
获赞
254
访问
103.1k
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int reverse_dir[] = {0, 2, 1, 4, 3}; // 1上2下3左4右的反方向映射
vector<pair<int, int>> path;
string s;
while (cin >> s) {
if (s == "0-0") break;
// 解析输入的方向和距离
size_t pos = s.find('-');
int d = stoi(s.substr(0, pos));
int dist = stoi(s.substr(pos + 1));
// 抵消反方向路径
while (dist > 0 && !path.empty()) {
auto &last = path.back();
if (last.first == reverse_dir[d]) {
if (last.second > dist) {
last.second -= dist;
dist = 0;
} else if (last.second == dist) {
path.pop_back();
dist = 0;
} else {
dist -= last.second;
path.pop_back();
}
...
登录后发布评论
暂无评论,来抢沙发