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

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

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

2019-11-11 00:51:05
字體:
來源:轉載
供稿:網友

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");    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 上思县| 炉霍县| 金塔县| 滦南县| 兴化市| 和顺县| 视频| 呼伦贝尔市| 宣汉县| 恩施市| 绿春县| 新晃| 白朗县| 天峻县| 天全县| 泰州市| 长春市| 平谷区| 丹凤县| 东至县| 武山县| 沂水县| 印江| 日照市| 瓮安县| 河曲县| 兴国县| 宝鸡市| 民勤县| 皮山县| 日土县| 山东省| 肥城市| 潞城市| 中西区| 桂平市| 伊宁市| 日喀则市| 浦县| 宜兰县| 安国市|