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 ...
随机推荐
- C/C++内存详解
众所周知,堆和栈是数据结构中的两种数据结构类型,堆是一种具有优先顺序的完全二叉树(或者说是一种优先队列,因为它在一定的优先顺序下满足队列先进先出的特点),排队打饭就是它的典型实例,栈是一种后进先出的数 ...
- Python常见数据结构-Set集合
集合基本特点 集合是无序的,且集合内无重复值. 集合不支持索引和切片 集合常见操作及方法 s1 = {1,2,3} s2 = {2,3,4} s1.add(4) #.add()方法添加一个元素 s1. ...
- C++值多态:传统多态与类型擦除之间
引言 我有一个显示屏模块: 模块上有一个128*64的单色显示屏,一个单片机(B)控制它显示的内容.单片机的I²C总线通过四边上的排针排母连接到其他单片机(A)上,A给B发送指令,B绘图. B可以向屏 ...
- web.xml配置参数context-param和init-param的区别
web.xml配置参数context-param和init-param的区别 (2009-04-13 10:29:01) 转载▼ 标签: 杂谈 分类: JavaEE web.xml里面可以定义两种参数 ...
- Python——详解__slots__,property和私有方法
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是Python专题的第11篇文章,我们来聊聊面向对象的一些进阶使用. __slots__ 如果你看过github当中一些大牛的代码,你会 ...
- PHP函数:array_rand
array_rand() - 从数组中随机取出一个或多个单元. 说明: array_rand ( array $array [, int $num = 1 ] ) : mixed 参数: array ...
- kubernetes删除pod,pod一直处于Terminating状态
删除pod,pod一直处于Terminating状态 [root@yxz-cluster01 deploy_yaml]# kubectl get pod -n yunanbao NAME READY ...
- ArangoDB 3.5:流事务API、搜索性能大幅提升、最短路径功能
ArangoDB 3.5 发布了.ArangoDB 是一个分布式原生的多模型数据库,具有灵活的文档.图形和键值数据模型.使用方便的 SQL 查询语言或 JavaScript 扩展构建高性能应用程序. ...
- js上传文件前判断获取文件大小并且加以判断
描述:要求浏览器单个上传文件大小不超过10M. 解决方案: var fileSize = $("#fileId")[0].files[0].size/(1024*1024);if( ...
- GoJS 教程新手入门(资源整理,解决方案)
以下几个是我在百度.谷歌 上能找到的比较全的GoJs的一些东西,希望对各位有所帮助! 如有外网网站不能访问请自行FQ GoJS官网 第一个推荐的是GoJS的一个类似于社区的问题讨论区,这里面初学者的一 ...