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

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

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

2019-11-11 00:48:30
字體:
來源:轉載
供稿:網友

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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鹿泉市| 都匀市| 鄱阳县| 南靖县| 崇州市| 若尔盖县| 三都| 太仆寺旗| 五河县| 邳州市| 闽清县| 塘沽区| 饶河县| 婺源县| 宁蒗| 界首市| 盐津县| 额济纳旗| 阿克苏市| 南岸区| 宁陵县| 大埔区| 修文县| 汤阴县| 邵武市| 华坪县| 福建省| 什邡市| 博爱县| 虹口区| 鄂尔多斯市| 上栗县| 开封县| 泽库县| 安龙县| 龙泉市| 沁阳市| 饶阳县| 奉贤区| 嘉禾县| 鄂伦春自治旗|