codeforces 669B B. Little Artem and Grasshopper(水题)
题目链接:
B. Little Artem and Grasshopper
2 seconds
256 megabytes
standard input
standard 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.
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 the i-th cell.
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
- 2
><
1 2
- FINITE
- 3
>><
2 1 1
- INFINITE
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
题意:
给每个格子的跳动方向和跳动的距离,问从第一个格子开始跳,是永远在这些格子里还是会跳出去;
思路:
模拟跳动,跳出去了就输出跳出去了,没跳出去当跳到原来跳过的格子上就会永远跳不出去;
AC代码:
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const ll mod=1e9+;
- const ll inf=1e15;
- const int N=1e5+;
- int n,a[N],vis[N];
- char s[N];
- int main()
- {
- memset(vis,,sizeof(vis));
- scanf("%d",&n);
- scanf("%s",s+);
- for(int i=;i<=n;i++)
- {
- scanf("%d",&a[i]);
- }
- int pos=;
- vis[]=;
- while()
- {
- if(s[pos]=='>')
- {
- if(pos+a[pos]>n)
- {
- printf("FINITE\n");
- return ;
- }
- else
- {
- if(vis[pos+a[pos]])
- {
- printf("INFINITE\n");
- return ;
- }
- else
- {
- pos+=a[pos];
- vis[pos]=;
- }
- }
- }
- else
- {
- if(pos-a[pos]<)
- {
- printf("FINITE\n");
- return ;
- }
- else
- {
- if(vis[pos-a[pos]])
- {
- printf("INFINITE\n");
- return ;
- }
- else
- {
- pos-=a[pos];
- vis[pos]=;
- }
- }
- }
- }
- return ;
- }
codeforces 669B B. Little Artem and Grasshopper(水题)的更多相关文章
- codeforces 669A A. Little Artem and Presents(水题)
题目链接: A. Little Artem and Presents time limit per test 2 seconds memory limit per test 256 megabytes ...
- codeforces 669C C. Little Artem and Matrix(水题)
题目链接: C. Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes i ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B. Little Artem and Grasshopper 模拟题
B. Little Artem and Grasshopper 题目连接: http://www.codeforces.com/contest/669/problem/B Description Li ...
- codeforces Gym 100187L L. Ministry of Truth 水题
L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...
- Codeforces Round #185 (Div. 2) B. Archer 水题
B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...
- Educational Codeforces Round 14 A. Fashion in Berland 水题
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...
- Codeforces Round #360 (Div. 2) A. Opponents 水题
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
- Codeforces Round #190 (Div. 2) 水果俩水题
后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...
- Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告
对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...
随机推荐
- android 根据图片名字获取图片id
public int getResource(String imageName){ Context ctx=getBaseContext(); int resId = getResources().g ...
- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
一.背景 最近的项目在用maven 进行install的时候,发现老师在控制台输出警告:[WARNING] Using platform encoding (UTF-8 actually) to co ...
- 详解在Visual Studio中使用git版本系统(图文)
http://www.codesky.net/article/201111/123474.html 这篇教程的预期,是希望没有任何版本使用基础的新手也可以掌握,所以细节较多,不当之处,欢迎指正. 第一 ...
- Basic Vim Configuration
原文: https://computers.tutsplus.com/tutorials/basic-vim-configuration--cms-21498 原来,vim的配置文件,.vimrc也是 ...
- django_session
基于cookie做用户验证时:敏感信息不适合放在cookie中 session依赖cookie session原理 cookie是保存在用户浏览器端的键值对 session是保存在服务器端的键值对 s ...
- hql 多对多查询
这种查询,hibernate 建议用 From Dealer s inner join fetch s.carSerieses cs 实现,注意这种实现只支持b.c,不支持b.cs. 如果要用b.c ...
- 嵌入式Linux驱动案例之中的一个
前几天解决一个嵌入式Linux驱动问题,做为一个案例进行记录. 本案例是一个CPU通过LocalBus总线訪问外围一个设备,详细设备是一个DSP器件.在实际应用中,性能要求非常高,对数据訪问速度提出比 ...
- Sencha touch 初体验
一.什么是Sencha Touch? Sencha Touch是一个应用手持移动设备的前端js框架,与extjs是同一个门派的,它继承了extjs的优点和缺点.功能很强大,效果很炫丽,效率不高. 二. ...
- node.js如何读取MySQL数据
先安装mysql模块. node.js默认安装时,模块文件放在 /usr/local/lib/node_modules 这个目录下,为了便宜管理,模块还是统一安装到这里好. $ cd /usr/loc ...
- CentOSyum操作
查看已经安装yum: yum list installed|grep mysql 查看yum: yum list|grep mysql 更新yum: rpm -ivh mysql-community- ...