博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Little Artem and Grasshopper
阅读量:5308 次
发布时间:2019-06-14

本文共 2256 字,大约阅读时间需要 7 分钟。

                   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
#include
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\n");break;}else if (time[num].b == 0 && num >= 0 && num

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

转载于:https://www.cnblogs.com/cattree/p/7397269.html

你可能感兴趣的文章
Swagger简单介绍
查看>>
Python数据分析入门案例
查看>>
vue-devtools 获取到 vuex store 和 Vue 实例的?
查看>>
Linux 中【./】和【/】和【.】之间有什么区别?
查看>>
内存地址对齐
查看>>
看门狗 (监控芯片)
查看>>
css背景样式
查看>>
JavaScript介绍
查看>>
开源网络漏洞扫描软件
查看>>
yum 命令跳过特定(指定)软件包升级方法
查看>>
创新课程管理系统数据库设计心得
查看>>
Hallo wolrd!
查看>>
16下学期进度条2
查看>>
Could not resolve view with name '***' in servlet with name 'dispatcher'
查看>>
Chapter 3 Phenomenon——12
查看>>
和小哥哥一起刷洛谷(1)
查看>>
遇麻烦,Win7+Ubuntu12.10+Archlinux12.10 +grub
查看>>
SqlBulkCopy大批量导入数据
查看>>
pandas 修改指定列中所有内容
查看>>
「 Luogu P2285 」打鼹鼠
查看>>