【题目链接】:http://codeforces.com/contest/239/problem/B

【题意】



给你一个长度为n的字符串,只包括‘<”>’以及数字0到9;

给你q个区间(n和q都小于等于100)

然后让你在这q个区间里面做一些操作;

有一个指针int,指向当前操作的位置,还有一个方向的int;

表示这个指针它要移动的方向;

每次对一个位置进行操作;

如果该位置是数字;

则把这个数字输出,然后这个数字递减1;

如果数字小于0了,则把它删掉;

然后把指针往方向int的方向移动一个单位;

如果是’>’或’<’则,把方向改成左或右;

然后往新的方向走,如果走了一步之后还是’<’或’>’

则把前一个’<’或’>’删掉;

问你最后0..9各输出了多少个;

【题解】



每次模拟一步即可;

直到cp指针跳出了区间为止;

可以用数组来模拟链表的删除过程;

对每个区间的操作,都把数组链表初始化一下即可;



【Number Of WA 】



0



【反思】



这种模拟删掉的过程用数组模拟链表的方法都比较方便;



【完整代码】

#include <bits/stdc++.h>
#define rep1(i,x,y) for (int i = x;i <= y;i++)
#define rep2(i,x,y) for (int i = x;i >= y;i--)
using namespace std; const int N = 100+10; int n,q,l,r,a[N][2],cp,dp,num;
int tot[10];
string s,s1; void get_next(){
int ll = a[cp][0],rr = a[cp][1],tcp = cp;
if (s1[cp]>='0' && s1[cp]<='9'){
cp = a[cp][dp];
num++;
tot[s1[tcp]-'0']++;
s1[tcp]--;
if (s1[tcp]<'0'){
a[ll][1] = rr;
a[rr][0] = ll;
}
}else{
if (s1[cp]=='<')
dp = 0;
else
dp = 1;
cp = a[cp][dp];
if (cp < l || cp > r) return;
if (s1[cp]>='0' && s1[cp]<='9') return;
a[ll][1] = rr,a[rr][0] = ll;
}
} int main(){
//freopen("D:\\rush.txt","r",stdin);
cin >> n >> q;
cin >> s;
s = ' ' + s;
rep1(i,1,q){
num = 0;
s1 = s;
cin >> l >> r;
rep1(j,l,r)
a[j][0] = j-1,a[j][1] = j+1;
rep1(j,0,9)
tot[j] = 0;
cp = l,dp = 1;
while (1){
get_next();
if (cp <l || cp>r) break;
}
rep1(j,0,9)
cout << tot[j] <<' ';
cout << endl;
}
return 0;
}

【codeforces 239B】Easy Tape Programming的更多相关文章

  1. 【Codeforces 1096D】Easy Problem

    [链接] 我是链接,点我呀:) [题意] 让你将一个字符串删掉一些字符. 使得字符串中不包含子序列"hard" 删掉每个字符的代价已知为ai 让你求出代价最小的方法. [题解] 设 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【codeforces 761C】Dasha and Password(动态规划做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 761C】Dasha and Password(贪心+枚举做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【32.22%】【codeforces 602B】Approximating a Constant Range

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【35.02%】【codeforces 734A】Vladik and flights

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【74.89%】【codeforces 551A】GukiZ and Contest

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 750F】New Year and Finding Roots

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【29.89%】【codeforces 734D】Anton and Chess

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. js异步队列之理解

    起因 最近看到一篇关于js异步执行顺序的解答,觉得有所收获,遂记录下来. marcotask和microtask js中异步队列可以分为两类,marcotask队列和microtask队列, marc ...

  2. CF508E (贪心+搜索+构造)

    题目大意:让你构造一个括号序列,括号匹配的方式类似于栈,给出从左数每个括号 到和它匹配的右括号的 最小和最大距离,让你输出一个合法括号序列 看错题了以为是二分图,然后写了搜索 贪心发现如果距离往小了填 ...

  3. 打包成ipa包

    http://zengwu3915.blog.163.com/blog/static/27834897201362831449893/?suggestedreading&wumii Xcode ...

  4. spring mvc 下载

    1.代码: response.setContentType("application/msword;charset=GBK"); try { response.setHeader( ...

  5. VUE:计算属性和监视

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. Golang-and-package-version-managment

    参考文章 学习Golang之后对golang中的版本管理,包管理等机制一直没有很好的琢磨,偶然想起还是觉得很有必要进行归纳,包管理使用起来简单,无非就是install,uninstall,list等, ...

  7. Tomcat example 应用信息泄漏漏洞及修复

    Tomcat 是一款开源的 Web 应用服务器软件.Tomcat 属于轻量级应用服务器,在中小型系统和并发访问用户不多的场合下被普遍使用,是开发和调试 JSP 程序的首选. 漏洞描述 Tomcat 在 ...

  8. test文件夹,测试类是放在src目录下的,test测试代码是代码啊,当然要放在代码文件夹下

    test文件夹,测试类是放在src目录下的,test测试代码是代码啊,当然要放在代码文件夹下 Maven的标准工程结构 Maven的标准工程结构如下: |-- pom.xml(maven的核心配置文件 ...

  9. npm --save 选项作用

    npm --save 选项作用 学习了:https://segmentfault.com/q/1010000000403629 -save和save-dev可以省掉你手动修改package.json文 ...

  10. 百度 谷歌 Twitter,这么多短链接服务(Short Url)究竟哪家强?

    一.短链接是什么 url=HPqdQ5VR3vA39x7ZWoWyNzwWnsDhTbh66BTpdzsJLroBDzFRm4JV-G818Zc027uZrwe7zxtxnD4H2FUahftpUK& ...