【codeforces 239B】Easy Tape Programming
【题目链接】: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的更多相关文章
- 【Codeforces 1096D】Easy Problem
[链接] 我是链接,点我呀:) [题意] 让你将一个字符串删掉一些字符. 使得字符串中不包含子序列"hard" 删掉每个字符的代价已知为ai 让你求出代价最小的方法. [题解] 设 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 761C】Dasha and Password(动态规划做法)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 761C】Dasha and Password(贪心+枚举做法)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【32.22%】【codeforces 602B】Approximating a Constant Range
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【35.02%】【codeforces 734A】Vladik and flights
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【74.89%】【codeforces 551A】GukiZ and Contest
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 750F】New Year and Finding Roots
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【29.89%】【codeforces 734D】Anton and Chess
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- 进入docker 容器内命令
docker exec :在运行的容器中执行命令 语法 docker exec [OPTIONS] CONTAINER COMMAND [ARG...] OPTIONS说明: -d :分离模式: 在后 ...
- github删除项目or仓库
1. 登录 github (要注册账号) 2. 登录后点击右上侧头像,选择 Your profile . 3. 选择Repositories,可以查看已有的库,选择要删除的库进入. 4. 选择Sett ...
- 用pycharm运行django项目
[点击]run -> Edit Configrations 弹出如下页面 点击“+” 点击Django server 在弹出页面的host填0.0.0.0 点击这个“文件夹” 点击‘+’后填下面 ...
- a标签设置高度不生效问题
<a>是内联元素 必须设置成块级元素block 才能有width和height 不过你可以又定义display:block再定义成display:inline 以避免在IE6下产生BUG ...
- [luogu] P4551 最长异或路径(贪心)
P4551 最长异或路径 题目描述 给定一棵\(n\)个点的带权树,结点下标从\(1\)开始到\(N\).寻找树中找两个结点,求最长的异或路径. 异或路径指的是指两个结点之间唯一路径上的所有边权的异或 ...
- 【BZOJ 1221】 [HNOI2001] 软件开发
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] /* 设一个超级源点S和超级汇点T S和2*i-1各连一条容量为ni的边. 花费为0 表示每天都会产生ni条要洗的毛巾 S和2*i各 ...
- cogs 304. [NOI2001] 方程的解数(meet in the middle)
304. [NOI2001] 方程的解数 ★★☆ 输入文件:equation1.in 输出文件:equation1.out 简单对比时间限制:3 s 内存限制:64 MB 问题描述 已 ...
- Ruby中写换行
Ruby中写换行 print("Hello,\nRuby\n!\n") print("Hello, Ruby ! ") 这两个竟然是一样的:就是说,可以直接回车 ...
- Hadoop自学笔记(一)常见Hadoop相关项目一览
本自学笔记来自于Yutube上的视频Hadoop系列.网址: https://www.youtube.com/watch?v=-TaAVaAwZTs(当中一个) 以后不再赘述 自学笔记,难免有各类错误 ...
- ubuntu中taglist和ctags安装,简单明了
1.使用命令安装ctags: sudo apt-get install ctags 2.安装taglist 下载: http://vim.sourceforge.net/scripts/downloa ...