题目链接:

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. minimum-moves-to-equal-array-elements-ii(好)

    https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ package com.company; import ...

  2. 菜鸟调错(十)——启动Tomcat报错“Unsupported major.minor version xxx ”

    近期项目更新JDK,由之前的1.7更新到1.8. 下载并安装好新的JDK以后,编译.启动Tomcat的时候,报错了.提示:"Unsupported major.minor version x ...

  3. 学会读懂 MySql 的慢查询日志

    在前边的博客<何时.怎样开启 MySql 日志?>中,我们了解到了怎样启用 MySql 的慢查询日志. 今天我们来看一下怎样去读懂这些慢查询日志.在跟踪慢查询日志之前.首先你得保证最少发生 ...

  4. Spring <context:annotation-config> 和 <context:component-scan>区别

    转自:http://www.cnblogs.com/leiOOlei/p/3713989.html <context:annotation-config> 和 <context:co ...

  5. ElasticSearchserver操作命令

    在win7环境,进入elasticsearch安装文件夹的bin文件夹: 1. elasticsearch.bat 就能够启动elasticsearch了.执行这个插件的优点是:elasticsear ...

  6. Mac终端处理MySql

    进入数据库: mysql -u root -p 随后输入密码:root   原文出处: GarveyCalvin的博客(@GarveyCalvin) MySQL有很多的可视化管理工具,比如“mysql ...

  7. 每天一点儿Java--list

    import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; /** * ...

  8. 腾讯云ubuntu memcached 安装

    ubuntu安装 sudo apt-get install  memcached 停止memcached服务:sudo systemctl stop memcached 激活memcached服务:s ...

  9. MongoDB之增删改查(一)

    本文主要介绍MongoDB数据库增删改查操作. 增 mongoDB和其它关系型数据库一样,通过insert来添加数据到集合中去. db.collectionName.insert(内容) 显示数据库中 ...

  10. 关于wpf中popup跟随鼠标移动显示

    最近在做一个画图工具,里面有一个功能是需要实现,当鼠标移动的时候在,鼠标的旁边显示坐标信息. 第一反应是想到了tooltip,但是tooltip有许多的限制,查询资料的过程中看到了popup,popu ...