• 洛谷 P1563 玩具谜题 (C/C++, JAVA)


    洛谷 P1563 玩具谜题

    /*
      P1563 玩具谜题
    */
    #include <iostream>
    #include <cstdio>
    #include <string>
    using namespace std;
    struct node 
    {
        int head;
        string name;
    }a[100005];
    int n,m,x,y;
    int main()
    {
        cin>>n>>m;
        for(int i=0;i<n;i++)
        {
            cin>>a[i].head>>a[i].name;
        }
        int now=0;
        for(int i=1;i<=m;i++)
        {
            cin>>x>>y;
            if(a[now].head==0&&x==0)now=(now+n-y)%n;
            else if(a[now].head==0&&x==1)now=(now+y)%n;
            else if(a[now].head==1&&x==0)now=(now+y)%n;
            else if(a[now].head==1&&x==1)now=(now+n-y)%n;
        }
        cout<<a[now].name<<endl;
        return 0;
    }
    
    import java.util.Scanner;
    class Node {
        static int cnt = 0;
        public int direction = 0;
        public String name = "";
        Node(int a, String b) {
            cnt++;
            direction = a; name = b;
        }
    }
    public class Main {
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int n = scan.nextInt(), m = scan.nextInt();
            Node[] toys = new Node[n];
            for(int i = 0; i < n; i++) {
                toys[i] = new Node(scan.nextInt(), scan.next());
            }
            int pos = 0;
            for(int i = 0; i < m; i++) {
                int a = scan.nextInt(), s = scan.nextInt();
                if(a == 0 && toys[pos].direction == 0) {
                    pos = (pos + n - s) % n;
                } else if (a == 0 && toys[pos].direction != 0) {
                    pos = (pos + s) % n;
                } else if(a == 1 && toys[pos].direction == 0) {
                    pos = (pos + s) % n;
                } else {
                    pos = (pos + n - s) % n;
                }
            }
            System.out.println(toys[pos].name);
        }
    }
    
  • 相关阅读:
    1142
    dbms_monitor开启/关闭会话跟踪
    mysql密码过期问题
    zabbix监控mysql
    12C -- ORA-65048 ORA-65048
    idea的快捷键
    IntelliJ IDEA的配置优化
    IDEA环境设置
    Java 中int、String的类型转换
    js数组去重
  • 原文地址:https://www.cnblogs.com/fromneptune/p/12218858.html
Copyright © 2020-2023  润新知