题目链接:

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. n*n的正方形网格中有多少个长方形

    n*n的正方形网格中有横竖各n+1条直线,其中,任意各取两条都可以组成一个长方形﹙正方形也是长方形﹚.所以长方形个数为C﹙n+2,2﹚×C﹙n+2,2﹚=﹙n+1﹚²n²/4个.如果正方形不算,则N= ...

  2. Android -- 开机启动无界面后台程序

    简单的说,这是一个没有界面的后台运行的应用程序 而且,还有一功能:开机自启动,启动运行一个服务 程序结构非常简单,两个类,一个是service的扩展类,一个是BroadcastReceiver扩展类 ...

  3. 11gR2 RAC 独占模式replace votedisk遭遇PROC-26,restore ocr遭遇CRS-4000、PROT-35

    原文链接:http://blog.itpub.net/23135684/viewspace-748816/ 11gR2 RAC系统的存储数据全然丢失,全部节点的软件都安装在本地磁盘中.本地磁盘保留了O ...

  4. Dance In Heap(一):浅析堆的申请释放及相应保护机制

    0×00 前面的话 在内存中,堆是一个很有趣的地方,因为它可以由用户去直接的进行分配与销毁,所以也产生了一些很有趣.奇思妙想的漏洞,像unlink漏洞.House系列漏洞等等.但是在学习的过程中,我们 ...

  5. 阿里巴巴为什么主推HSF?比Dubbo有哪些优势?

    作者:匿名用户链接:https://www.zhihu.com/question/39560697/answer/187538165来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...

  6. Foundation框架 - NSException类

    NSException类 WBStudentManager.h #import <Foundation/Foundation.h> NSString* const NameInvalidE ...

  7. 【每日Scrum】第三天(4.24) TD学生助手Sprint2站立会议

    站立会议 组员 昨天 今天 困难 签到 刘铸辉 (组长) 今天主要看了多事件处理的内容然后改了下界面, 和小楠重写架构,使代码更加简洁,并增加了几个界面 架构太难,数据库字段总出问题 Y 刘静 添加事 ...

  8. smali函数分析

    一.函数调用 smali中的函数和成员变量也分为两种,分别为 direct 和 virtual 两者的区别 1.direct method 是指private函数 2.virtual method 是 ...

  9. 第 2 章 第 9 题 顺序 & 二分搜索效率分析问题

    问题分析 顺序搜索的时间复杂度是O( n ),二分搜索的时间复杂度级别是O( lgn ).但这并不代表二分的时间开销就一定比顺序的小,因为二分搜索有个前提:元素必须要是有序的.如果仅仅为了二分搜索几个 ...

  10. 开启kbmmw 5.09 中的XML-RPC和 JSON-RPC 服务

    kbmmw 5.09 里面增加了XML-RPC和 JSON-RPC 服务支持,但是默认没有开启. 需要在安装前,修改kbmMWConfig.inc文件. 加入以下定义 {$DEFINE KBMMW_J ...