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

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

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

2019-11-11 00:04:53
字體:
來源:轉載
供稿:網友

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


上一篇:排序算法 之 快速排序

下一篇:poj1316

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 石棉县| 房山区| 罗平县| 庆元县| 泰宁县| 侯马市| 合肥市| 广宁县| 海原县| 海门市| 缙云县| 邹平县| 台前县| 宁阳县| 齐河县| 铁力市| 阿拉尔市| 凌云县| 闽侯县| 黔东| 郸城县| 沙河市| 溧阳市| 星子县| 海口市| 马山县| 长阳| 维西| 石渠县| 墨脱县| 溆浦县| 新乡县| 蓬莱市| 天峻县| 垦利县| 体育| 黔西| 麦盖提县| 库伦旗| 内黄县| 沾化县|