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 ...
随机推荐
- sublime快捷键设置
1.sublime自带的快捷键设置:这里的super在mac下是指command键 右边的内容表示用户自定义的快捷键:比如如图所示command+d表示复制光标所在行 常用操作:复制粘贴什么的太常用的 ...
- 借助树莓派模拟Wimonitor并实现WiFi窃听和嗅探
Wimonitor是一款非常优秀的黑客工具,它不仅可以帮渗透测试人员省去配置虚拟机和无线网卡等一系列麻烦事,而且它的Web接口配置起来也非常的方便.实际上,它就是一款TP-Link-MR3020路由器 ...
- log4net报错Could not load type 'System.Security.Claims.ClaimsIdentity'
使用log4net,在win7上可以正常使用,但是在部分xp电脑上可以生成access数据库,但是无法写数据到mdb 排除了程序原因,怀疑是xp缺少什么dll之类的 偶然查到log4net的调试方法: ...
- IOS 开发推荐经常使用lib
1. Mantle Mantle 让我们能简化 Cocoa 和 Cocoa Touch 应用的 model 层.简单点说.程序中常常要进行网络请求,请求到得通常是 json 字符串.我们通常会建一个 ...
- Go语言阅读小笔记,来自知呼达达关于unsafe.Pointer的分享.
第一式 - 获得Slice和String的内存数据 func stringPointer(s string) unsafe.Pointer { p := (*reflect.StringHeader) ...
- Jenkins系列之-—08 实现SQL脚本批量执行
公司内部推广DevOps,所有目前在维护阶段和开发阶段项目全部配置上了自动发布.采用Jenkins+SVN+ANT,之后批量执行SQL语句的实现提上日程 一.环境 Linux环境 安装ANT工具,且下 ...
- TNS-01201: Listener cannot find executablen 错误
近期在启动监听器的时候收到了TNS-01201: Listener cannot find executable...的错误提示.这个错误还真是一个一直没有碰到过的错误.咋一看还真不明确是怎么一回事呢 ...
- PCIE、UART、HDA、I2C、SMBUS、SPI、eSPI、USB、PS2、CAN、SDIO等数据传输协议简介
M.2 wife一般支持USB.SDIO.PCIE三种传输 1.摄像头 (1)MIPI CSI (2)USB mipi摄像头模组IC简单便宜(小),应为一般把ADC解码在CPU端. MIPI摄像头简介 ...
- hdoj 5094 Maze 【BFS + 状态压缩】 【好多坑】
Maze Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Others) Total Sub ...
- kubernetes滚动更新
系列目录 简介 当kubernetes集群中的某个服务需要升级时,传统的做法是,先将要更新的服务下线,业务停止后再更新版本和配置,然后重新启动并提供服务.如果业务集群规模较大时,这个工作就变成了一个挑 ...