Codeforce 239 B. Easy Tape Programming
There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts.
- Current character pointer (CP);
- Direction pointer (DP) which can point left or right;
Initially CP points to the leftmost character of the sequence and DP points to the right.
We repeat the following steps until the first moment that CP points to somewhere outside the sequence.
- If CP is pointing to a digit the interpreter prints that digit then CP moves one step according to the direction of DP. After that the value of the printed digit in the sequence decreases by one. If the printed digit was 0 then it cannot be decreased therefore it's erased from the sequence and the length of the sequence decreases by one.
- If CP is pointing to "<" or ">" then the direction of DP changes to "left" or "right" correspondingly. Then CP moves one step according to DP. If the new character that CP is pointing to is "<" or ">" then the previous character will be erased from the sequence.
If at any moment the CP goes outside of the sequence the execution is terminated.
It's obvious the every program in this language terminates after some steps.
We have a sequence s1, s2, ..., sn of "<", ">" and digits. You should answer q queries. Each query gives you l and r and asks how many of each digit will be printed if we run the sequence sl, sl + 1, ..., sr as an independent program in this language.
Input
The first line of input contains two integers n and q (1 ≤ n, q ≤ 100) — represents the length of the sequence s and the number of queries.
The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces.
The next q lines each contains two integers li and ri (1 ≤ li ≤ ri ≤ n) — the i-th query.
Output
For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input.
Examples
input
7 4
1>3>22<
1 3
4 7
7 7
1 7
output
0 1 0 1 0 0 0 0 0 0
2 2 2 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
2 3 2 1 0 0 0 0 0 0
这是一道模拟题,模拟一个他叙述的过程就是一个指针一个方向标记遇到>改成向右的方向,遇见<改成向左,每次遇到数字输出数字并将数字减一,减到零就删去,遇到连续的两个方向就删去先访问的那一个,给定一个子区间,求0-9输出了几遍。
#include<bits/stdc++.h>
#define Swap(a,b) a^=b^=a^=b
#define cini(n) scanf("%d",&n)
#define cinl(n) scanf("%lld",&n)
#define cinc(n) scanf("%c",&n)
#define coui(n) printf("%d",n)
#define couc(n) printf("%c",n)
#define coul(n) printf("%lld",n)
#define speed ios_base::sync_with_stdio(0);//切不可用scnaf;
#define Max(a,b) a>b?a:b
#define Min(a,b) a<b?a:b
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int maxn=1e6+10;
const double esp=1e-9;
int m,n,x,y,lll[maxn],rr[maxn];
int l[110];
int r[110];
int ans[10];
string w;
int a[10];
int main()
{
cin>>n>>m>>w;
while(m--)
{
int l,r;
cin>>l>>r;
memset(a,0,sizeof(a));
string t=w.substr(l-1,r-l+1);
int lll=0,rr=1;
int E=t.size();
while(lll>=0&&lll<E)
{
if(t[lll]>='0'&&t[lll]<='9')
{
a[t[lll]-'0']++;
t[lll]--;
if(t[lll]<'0')
{
t.erase(lll,1);
if(rr<0)lll+=rr;
}
else lll+=rr;
}
else
{
if(t[lll]=='<') rr=-1;
else rr=1;
if(lll+rr>=0&&lll+rr<E&&(t[lll+rr]=='<'||t[lll+rr]=='>'))
{
t.erase(lll,1);
if(rr<0) lll+=rr;
}
else lll+=rr;
}
}
for(int i=0;i<10; i++)
cout<<a[i]<<' ';
cout<<endl;
}
return 0;
}
Codeforce 239 B. Easy Tape Programming的更多相关文章
- 【codeforces 239B】Easy Tape Programming
[题目链接]:http://codeforces.com/contest/239/problem/B [题意] 给你一个长度为n的字符串,只包括'<">'以及数字0到9; 给你q ...
- Codeforces Round #148 (Div. 2)
A. Two Bags of Potatoes 枚举倍数. B. Easy Tape Programming (待补) C. Not Wool Sequences 考虑前缀异或和. \[answer ...
- 嵌入式web服务
:boa.thttpd.mini_httpd.shttpd.lighttpd.goaheand.appweb和apache等. Boa 1.介绍 Boa诞生于1991年,作者Paul Philips. ...
- Range Minimum Query and Lowest Common Ancestor
作者:danielp 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=lowestCommonAnc ...
- 嵌入式设备web服务器比较
目录(?)[-] Boa Thttpd Mini_httpd Shttpd Lighttpd Goahead AppWeb Apache 开发语言和开发工具 结论 备注 现在在嵌入式设备中所使用的 ...
- 5步搭建GO环境
Easy Go Programming Setup for Windows Dec 23, 2014 I’ve had to do this more than once recently, so I ...
- 使用 Rcpp
正如我们所提到的那样,并行计算只有在每次迭代都是独立的情况下才可行,这样最终结果才不会依赖运行顺序.然而,并非所有任务都像这样理想.因此,并行计算可能会受到影响.那么怎样才能使算法快速运行,并且可以轻 ...
- AwesomePerfCpp 性能优化
Contents Talks Articles Sites/Blogs Tools Libraries Books About Talks 2013: Going Native 2013 - Andr ...
- OpenMP 并行程序设计入门
OpenMP 是一个编译器指令和库函数的集合,主要是为共享式存储计算机上的并行程序设计使用的. 0. 一段使用 OpenMP 的并行程序 #include <stdio.h> #inclu ...
随机推荐
- python 面向对象反射以及内置方法
一.反射 什么是反射:可以用字符串的方式去访问对象的属性,调用对象的方法(但是不能去访问方法),python中一切皆对象,都可以使用放射. 反射的四种方法: hasattr:hasattr(objec ...
- uni-app同步缓存值 设置 读取 删除
A页面 <view class="go-to-tab" @tap="gotologin"> 去login页面 </view> msg : ...
- Ant概念
Ant是基于Java的.可以跨平台的项目编译和生成工具.
- Problem F Free Weights
二分答案. 思路:对于二分给定的mid,即当前允许移动的最大重量,我们可以把小于改重量的标记一下,然后把没有标记的按照顺序放到另一个数组,然后判断是否满足两两相同. #include<bits/ ...
- linux常用命令--文件搜索
find / -name file1 从 '/' 开始进入根文件系统搜索文件和目录 find / -user user1 搜索属于用户 'user1' 的文件和目录 find /home/user1 ...
- 4.加密与token(node+express)
一. 敏感数据加密1.安装并引入中间件 npm install utility const utils = require('utility')2.加密方法 function ...
- Jmeter工具 组件简单认识
JMETER 所有的组件(元素)都是基于测试计划的,先有测试计划然后才有 JMETER 组件 JMETER 核心组件1.JMETER中的 Threads 类似与线程数,每一个线程数代表一个虚拟用户:测 ...
- 使用mysqlbinlog查看二进制日志
(一)mysqlbinlog工具介绍 binlog类型是二进制的,也就意味着我们没法直接打开看,MySQL提供了mysqlbinlog来查看二进制日志,该工具类似于Oracle的logminer.my ...
- JDBC教程——检视阅读
JDBC教程--检视阅读 参考 JDBC教程--W3Cschool JDBC教程--一点教程,有高级部分 JDBC教程--易百 JDBC入门教程 – 终极指南 略读 三层架构详解,JDBC在数据访问层 ...
- MVC-基础01
MVC体系结构将应用程序分成三个主要组件:模型(Model).视图(View).和控制器(Controller).在ASP.NET MVC应用程序中,数据操控的逻辑包含在Models文件夹下,数据的展 ...