Educational Codeforces Round 1 B. Queries on a String 暴力
2015-11-15 09:09
483 查看
B. Queries on a String
Time Limit: 20 SecMemory Limit: 256 MB
题目连接
http://codeforces.com/contest/598/problem/BDescription
You are given a string s and should process m queries. Each query is described by two 1-based indices li, ri and integer ki. It means that you should cyclically shift the substring s[li... ri] ki times. The queries should be processed one after another in the order they are given.One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.
For example, if the string s is abacaba and the query is l1 = 3, r1 = 6, k1 = 1 then the answer is abbacaa. If after that we would process the query l2 = 1, r2 = 4, k2 = 2 then we would get the string baabcaa.
Input
The first line of the input contains the string s (1 ≤ |s| ≤ 10 000) in its initial state, where |s| stands for the length of s. It contains only lowercase English letters.
Second line contains a single integer m (1 ≤ m ≤ 300) — the number of queries.
The i-th of the next m lines contains three integers li, ri and ki (1 ≤ li ≤ ri ≤ |s|, 1 ≤ ki ≤ 1 000 000) — the description of the i-th query.
Output
Print the resulting string s after processing all m queries.
Sample Input
abacaba 2 3 6 1 1 4 2
Sample Output
baabcaa
HINT
题意给你一个字符串,然后有Q次操作,每次操作可以使得区间的字符串向右平移K个字符
然后问你最后的字符是什么模样
题解:
询问只有300个,所以可以直接暴力就好了
代码
#include<iostream> using namespace std; int main() { string s1,s2; cin>>s1; s2=s1; int q;cin>>q; while(q--) { int l,r,k;cin>>l>>r>>k; l--,r--; int len = r-l+1;k%=len; for(int i=0;i<len;i++) { s2[(i+k)%len+l]=s1[l+i]; } for(int i=l;i<=r;i++) s1[i]=s2[i]; } cout<<s1<<endl; }
相关文章推荐
- 苹果开发 笔记(93) UITableView 的编辑模式
- 如何使用UIAutomation进行iOS 自动化测试(Part I)
- 有一个无效 SelectedValue,因为它不在项目列表中。
- 一. 使用代码实现UITableView的cell自定义高度-类似于微博主页
- IOS的UI基础02
- 为 Key-Value 数据库实现MVCC 事务
- UITableView 滚动到指定行cell
- GPUImage API文档之GPUImageContext类
- UISlider自定义滑块大小
- ios UiView转换成UIImage
- iOS 开发之带输入框的UIAlertView
- 基于POM(page oriented model)的UI测试脚本编写
- IOS之UIImageView--小实例项目--带音效的拳皇动画
- Arduino与Android蓝牙通信笔记
- easyui datagrid 编辑状态时,为列添加文本改变事件
- Dimensionality Reduction Techniques for Data Visualization
- 杭电ACM3117——Crixalis's Equipment
- 设计模式-生成器模式(Builder)
- require学习笔记总结
- confluence5.8.10的使用