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
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; }
相关文章推荐
- CodeForces 641 E.Little Artem and Time Machine(BIT+map)
- codeforces 669B B. Little Artem and Grasshopper(水题)
- Codeforces 669B Little Artem and Grasshopper【思维+模拟】
- CodeForces 641 B.Little Artem and Matrix(水~)
- codeforces 641 C Little Artem and Dance
- ACM刷题之Codeforces———— Little Artem and Grasshopper
- CodeForces 641 C.Little Artem and Dance(水~)
- codeforces 668C - Little Artem and Random Variable
- Codeforces Round #348 (div 2) B - Little Artem and Grasshopper
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition)-B. Little Artem and Grasshopper(模拟)
- B. Little Artem and Grasshopper
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B. Little Artem and Grasshopper 模拟题
- CF Round #348 Div. 2 A. Little Artem and Present B. Little Artem and Grasshopper C. Little Artem and
- CodeForces 669A Little Artem and Presents
- [2-SAT] Codeforces 668E #348 (VK Cup 2016 Round 2, Div. 1 Edition) E. Little Artem and 2-SAT
- 【CodeForces】669A - Little Artem and Presents(找规律)
- Codeforces 669A Little Artem and Presents(数量不同送礼物)
- codeforces 669D D. Little Artem and Dance(乱搞题)
- 【CodeForces】669A - Little Artem and Presents
- ACM刷题之Codeforces————Little Artem and Presents