题目链接:

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

题意:

给每个格子的跳动方向和跳动的距离,问从第一个格子开始跳,是永远在这些格子里还是会跳出去;

思路:

模拟跳动,跳出去了就输出跳出去了,没跳出去当跳到原来跳过的格子上就会永远跳不出去;

AC代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+;
const ll inf=1e15;
const int N=1e5+;
int n,a[N],vis[N];
char s[N];
int main()
{
memset(vis,,sizeof(vis));
scanf("%d",&n);
scanf("%s",s+);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
int pos=;
vis[]=;
while()
{
if(s[pos]=='>')
{
if(pos+a[pos]>n)
{
printf("FINITE\n");
return ;
}
else
{
if(vis[pos+a[pos]])
{
printf("INFINITE\n");
return ;
}
else
{
pos+=a[pos];
vis[pos]=;
}
}
}
else
{ if(pos-a[pos]<)
{
printf("FINITE\n");
return ;
}
else
{
if(vis[pos-a[pos]])
{
printf("INFINITE\n");
return ;
}
else
{
pos-=a[pos];
vis[pos]=;
}
} }
} return ;
}

codeforces 669B B. Little Artem and Grasshopper(水题)的更多相关文章

  1. codeforces 669A A. Little Artem and Presents(水题)

    题目链接: A. Little Artem and Presents time limit per test 2 seconds memory limit per test 256 megabytes ...

  2. codeforces 669C C. Little Artem and Matrix(水题)

    题目链接: C. Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes i ...

  3. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B. Little Artem and Grasshopper 模拟题

    B. Little Artem and Grasshopper 题目连接: http://www.codeforces.com/contest/669/problem/B Description Li ...

  4. codeforces Gym 100187L L. Ministry of Truth 水题

    L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  5. Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  6. Educational Codeforces Round 14 A. Fashion in Berland 水题

    A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...

  7. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  8. Codeforces Round #190 (Div. 2) 水果俩水题

    后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...

  9. Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告

    对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...

随机推荐

  1. 【Navicat preminm】64位的Navicat preminm注册

    百度云盘 技术-->Navicat preminm+破解

  2. 45个非常有用的Oracle查询语句(转自开源中国社区)

    日期/时间 相关查询 获取当前月份的第一天 运行这个命令能快速返回当前月份的第一天.你可以用任何的日期值替换 “SYSDATE”来指定查询的日期. SELECT TRUNC (SYSDATE, 'MO ...

  3. scala工具sbt的安装和使用;idea如何创建scala项目

    scala的sbt类似于java的maven mac:brew install sbt linux:yum Install sbt 或者下载二机制包 使用sbt需要想mvn一样搭建公司私服,不然,下载 ...

  4. php程序调试: xdebug的配置

    怎样在phpeclipse中像调试Java程序一样调试php呢? XDebug的版本号非常多,打开http://xdebug.org/index.php.把站点细致看一下,你会发现有句"If ...

  5. 【LeetCode-面试算法经典-Java实现】【002-Add Two Numbers (单链表表示的两个数相加)】

    [002-Add Two Numbers (单链表表示的两个数相加)] 原题 You are given two linked lists representing two non-negative ...

  6. python的多线程问题

    在对文件进行预处理的时候,由于有的文件有太大,处理很慢,用python处理是先分割文件,然后每个文件起一个线程处理,启了10个线程,结果还比不起线程慢一些,改成多进程之后就好了. 使用multipro ...

  7. 【每日Scrum】第六天(4.16) TD学生助手Sprint1阶段性成果

    TD学生助手Sprint1阶段性成果(4.16) 任务看板 站立会议内容 组员 昨天 今天 困难 签到 刘铸辉 (组长) 和叶姐,静姐修改页面布局和图片显示,保证界面的亲切. 和大家一起做演示PPT, ...

  8. javaweb dev 入

    ::::关于jsp页面和servlet之间传递参数 JSP与 servlet之间的传值有两种情况:JSP -> servlet, servlet -> JSP. 通过对象 request和 ...

  9. Apache/Nigix + Tomcat + 负载均衡

    Part I: Apache + Tomcat + 负载均衡 http://www.open-open.com/lib/view/open1350612892352.html http://micha ...

  10. 实记处理mongodb的NUMA问题

    一次在启动mongodb的过程中,出现过NUMA这个问题, mongodb日志显示如下: WARNING: You are running on a NUMA machine. We suggest ...