• 洛谷 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);
        }
    }
    
  • 相关阅读:
    webmagic使用
    网站文件下载链接
    正则表达式
    JS 页面刷新或重载
    History
    【问题&解决】fonts/fontawesome-webfont.woff2 404 (Not Found)
    ckeditor的使用
    Windows Server 2012 R2 或 2016 无法安装 .Net 3.5.1
    自定义配置文件的读取
    MVC中上传文件大小限制的解决办法
  • 原文地址:https://www.cnblogs.com/fromneptune/p/12218858.html
Copyright © 2020-2023  润新知