zoukankan      html  css  js  c++  java
  • Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B

    B. Little Artem and Grasshopper
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    题意:有n个区域 每个区域给一个固定跳跃方向‘>’代表向右 和 ‘<’代表向左 接下来的一行代表这个从这个区域能跳跃多远

            若能一直跳跃输出INFINITE 否则输出FINITE

    题解:存储每个位置的跳跃后的状态 暴力模拟过程

             标记 若在某一个位置重复出现 则说明能够一直跳跃输出INFINITE 若跳出1~n的范围则输出FINITE

     1 #include<iostream>
     2  #include<cstring>
     3  #include<cstdio>
     4  #include<queue>
     5  #include<stack>
     6  #include<map>
     7  #include<set>
     8  #include<algorithm>
     9  #define ll __int64
    10  #define pi acos(-1.0)
    11  #define mod 1
    12  #define maxn 10000
    13  using namespace std;
    14  int n;
    15  map<int,char> mp;
    16  map<int,int> to;
    17  map<int,int> mpp;
    18  int exm;
    19  int main()
    20  {
    21      mp.clear();
    22      mpp.clear();
    23      to.clear();
    24      scanf("%d",&n);
    25      getchar();
    26      for(int i=1;i<=n;i++)
    27         scanf("%c",&mp[i]);
    28      for(int i=1;i<=n;i++)
    29      {
    30          scanf("%d",&exm);
    31          if(mp[i]=='>')
    32            to[i]=i+exm;
    33          else
    34            to[i]=i-exm;
    35     }
    36     exm=1;
    37     int flag=0;
    38     while(1)
    39     {
    40         if(exm>n||exm<1)
    41         {
    42             flag=0;
    43             break;
    44         }
    45         if(mpp[exm]==1)
    46         {
    47             flag=1;
    48             break;
    49         }
    50         mpp[exm]=1;
    51         exm=to[exm];    
    52     }
    53     if(flag)
    54    cout<<"INFINITE"<<endl; 
    55    else
    56     cout<<"FINITE"<<endl;    
    57      return 0;
    58  }
  • 相关阅读:
    hadoop系列二:HDFS文件系统的命令及JAVA客户端API
    hadoop系列一:hadoop集群安装
    解决tomcat下面部署多个项目log4j的日志输出会集中输出到一个项目中的问题
    HandlerMethodArgumentResolver数据绑定无效
    MyBatis 元素类型为 "configuration" 的内容必须匹配 ".....
    jquery.uploadify 异常 “__flash__removeCallback”未定义
    fusioncharts图例(legend)属性
    Flex Error #2156问题
    HTML注释引起的问题
    Asp.net Mvc4 使用Cas单点登录
  • 原文地址:https://www.cnblogs.com/hsd-/p/5429173.html
Copyright © 2011-2022 走看看