zoukankan      html  css  js  c++  java
  • Little Artem and Grasshopper

                       B. Little Artem and Grasshopper

                            time limit per test

                            2 seconds

                            memory limit per test

                            256 megabytes

      Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.

    The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.

    Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.

    Output

    Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).

    Examples
    Input
    2
    ><
    1 2
    
    Output
    FINITE
    
    Input
    3
    >><
    2 1 1
    
    Output
    INFINITE

    Note

    In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.

    Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.

     

    很水的一个题

    题意:

       有一条通道,是由一个一个格子组成,每个格子上分别标记着下一步要走的方向和对应的步数,出口是最左端或者最右端。问你能不能走出去。

    思路:

       如果某一步和之前走过的某一步重复了,那么就陷入死循环中无法出去,注意判断是否陷入死循环。

       还有,不要忽略这种情况 >>>>>

                      1 1 1 1 1   这样子也可以走出去奥~~~

    AC代码:

    #include<iostream>
    #include<stdio.h>
    using namespace std;
    struct state
    {
    char a;
    int b;
    }time[100004];//定义一个结构体数组来存放格子的规则
    int main()
    {
    int n;
    int step = 0;
    while (~scanf("%d", &n))
    {
    getchar();//吃掉回车
    for (int i = 0; i < n; i++)
    {
    scanf("%c", &time[i].a);
    }
    //getchar();
    for (int i = 0; i < n; i++)
    {
    scanf("%d", &time[i].b);
    }
    int num = 0;
    int ans = 0;
    while(1)
    {
    if (time[num].a == '>')
    {
    ans = num;
    num += time[num].b;//此时此刻timr[num]这个已经用过了,num用来记录走到哪里了。
    time[ans].b = 0;//所以在这里给他归零
    }
    else
    {
    ans = num;
    num -= time[num].b;
    time[ans].b = 0;
    }
    
    if (num<0 || num>=n)//注意这个等号很重要,我就没写结果漏掉了一种情况
    {
    printf("FINITE
    ");
    break;
    }
    else if (time[num].b == 0 && num >= 0 && num <n)//判断说不是陷入了死循环,咦嘻嘻
    {
    printf("INFINITE
    ");
    break;
    }
    }
    }
    return 0;
    }

    今天也是元气满满的一天,good luck!

    我想要变得高一点,最好能伸手给你一片天。
  • 相关阅读:
    angularjs 学习笔记(一)
    iconfont项目成员添加不进去的问题
    服务器webapi集成极光推送学习笔记
    winform closing事件注册
    asp.net core webapi 似乎未安装在 IIS 中承载 .NET Core 项目所需的 AspNetCoreModule。请尝试修复 Visual Studio 以纠正该问题。
    css 行内元素设置宽高
    透过浏览器看HTTP缓存[转载]
    矢量字体图标
    HTML5新特性之WebRTC[转]
    一个前后端分离方案[转载]
  • 原文地址:https://www.cnblogs.com/cattree/p/7397269.html
Copyright © 2011-2022 走看看