前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【第17题】 [NOIP2016 提高组] 玩具谜题

【第17题】 [NOIP2016 提高组] 玩具谜题

作者头像
小码匠
发布2023-08-31 14:07:20
1570
发布2023-08-31 14:07:20
举报
文章被收录于专栏:小码匠和老码农

题目:

题目原文请移步下面的链接

  • https://www.luogu.com.cn/problem/P1563
    • 参考题解:https://www.luogu.com.cn/problem/solution/P1563
  • 标签:模拟
  • 难度:普及-

题解

思路
  • 纯模拟题,思路比较简单,就不赘述了;
  • 题解大家可移步看这里,很多童鞋写了各种解法。
    • https://www.luogu.com.cn/problem/solution/P1563
代码
代码语言:javascript
复制
#include <bits/stdc++.h>

using namespace std;
#define endl '\n';

struct edge {
    string s;
    bool b;
};

int instruct(bool x, bool y, int z) {
    if (x ^ y) {
        return z;
    } else {
        return -z;
    }
}

void best_coder() {
    int n, m;
    cin >> n >> m;
    vector<edge> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].b >> v[i].s;
    }
    int t = 0;
    int x, y;
    for (int i = 0; i < m; ++i) {
        cin >> x >> y;
        t += instruct(v[t].b, x, y);
        if (t <= 0) {
            t += n;
        }
        if (t >= n) {
            t %= n;
        }
    }
    cout << v[t].s;
}

void happy_coder() {

}

int main() {
    // 提升cin、cout效率
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // 小码匠
    best_coder();

    // 最优解
    // happy_coder();

    // 返回
    return 0;
}

END

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-05-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 小码匠和老码农 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题目:
  • 题解
    • 思路
      • 代码
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档