您的位置:首页 > 运维架构

CodeForces 641 A.Little Artem and Grasshopper(水~)

2017-04-28 11:34 363 查看
Description

1~n上每个点都有一步操作,即往左或往右走若干步,不用考虑经过点的操作,起点在1,问是否能够走出区间[1,n]

Input

第一行一整数n,之后一个长度为n的字符串表示每个点上操作的方向,之后n个整数d[i]表示到达i点处后需要走几步

Output

如果可以走出[1,n]则输出FINITE,否则输出INFINITE

Sample Input

2

<

1 2

Sample Output

FINITE

Solution

一步步走,走到哪儿就把哪标记,如果走到一个已经被标记过的点则说明走不出去了,否则接着走一直到走出去为止

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 111111
int n,d[maxn],flag[maxn];
char s[maxn];
int main()
{
while(~scanf("%d",&n))
{
scanf("%s",s+1);
for(int i=1;i<=n;i++)scanf("%d",&d[i]);
memset(flag,0,sizeof(flag));
int pos=1,gg;
while(1)
{
flag[pos]=1;
if(s[pos]=='<')pos-=d[pos];
else pos+=d[pos];
if(pos<1||pos>n)
{
gg=1;
break;
}
if(flag[pos])
{
gg=0;
break;
}
}
printf("%s\n",gg?"FINITE":"INFINITE");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: