国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Codeforces 669B Little Artem and Grasshopper【思維+模擬】

2019-11-11 02:07:49
字體:
來源:轉載
供稿:網友

B. Little Artem and Grasshoppertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard 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 thei-th cell.

Output

Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).

ExamplesInput
2><1 2Output
FINITEInput
3>><2 1 1Output
INFINITENote

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*N的地方,每個格子都有一個方向鍵,表示走到這個位子的時候需要往哪個方向走,走的長度為di.

問是否能夠走出這個地方,從左邊出去或者右邊出去都算出去。

思路:

對于不能出去的情況,其實就是出現了某個格子走過兩次的時候。如果對于一個格子來講走過了第一次還要走第二次,那么肯定再走下去還是會回到這個位子,會再次走環路。

那么我們設定一個數組vis【i】表示位子i是否已經走過了,如果已經走過了又走了上去,那么就是肯定無法出去的情況。相反,如果某一時刻走了出去,就是能夠走出去的情況。過程維護一下就行了。

Ac代碼:

#include<stdio.h>#include<string.h>using namespace std;char a[1000000];int vis[1000000];int d[1000000];int main(){    int n;    while(~scanf("%d",&n))    {        scanf("%s",a+1);        memset(vis,0,sizeof(vis));        for(int i=1;i<=n;i++)scanf("%d",&d[i]);        int flag=0;        int now=1;        while(now<=n&&now>=1)        {            //printf("%d/n",now);            if(vis[now]==1)            {                flag=0;                break;            }            vis[now]=1;            if(a[now]=='<')now-=d[now];            else now+=d[now];            if(now>n||now<1)            {                flag=1;                break;            }        }        if(flag==1)printf("FINITE/n");        else printf("INFINITE/n");    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 云阳县| 五常市| 舒兰市| 临武县| 合肥市| 汕头市| 绩溪县| 深州市| 新邵县| 泾川县| 临夏市| 治多县| 中宁县| 宁明县| 区。| 和政县| 高安市| 调兵山市| 大悟县| 嵊泗县| 福海县| 宜昌市| 延安市| 福清市| 文化| 闸北区| 会东县| 东安县| 华亭县| 灵川县| 凌海市| 德江县| 青浦区| 湖南省| 蒲城县| 阳城县| 大城县| 若尔盖县| 巴青县| 平南县| 宕昌县|