【Educational Codeforces Round 1B】【字符串平移 水题】Queries on a String 字符串平移水题
来源:互联网 发布:罗云彬的编程乐园 编辑:程序博客网 时间:2024/06/06 07:32
#include<stdio.h>#include<string.h>#include<ctype.h>#include<math.h>#include<iostream>#include<string>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}const int N=10010,M=0,Z=1e9+7,ms63=1061109567;int casenum,casei;char s[N];char tmp[N];int main(){while(~scanf("%s",s+1)){int m;scanf("%d",&m);int l,r,k;while(m--){scanf("%d%d%d",&l,&r,&k);k%=(r-l+1);int g=0;for(int i=r-(k-1);i<=r;i++)tmp[++g]=s[i];for(int i=l;i<=r-k;i++)tmp[++g]=s[i];for(int i=1,j=l;i<=g;i++,j++)s[j]=tmp[i];}puts(s+1);}return 0;}/*【题意】给你一个长度在[1,10000]范围内的字符串,让你执行m次操作对于每个操作,我们要对这个字符串[l,r]区间范围的数,向右做旋转式平移k次(注,向右的旋转式平移就是位置p是由位置p-1的数转移得,位置l是由位置r转移得)让你输出所有操作完成之后的串。(1<=m<=300,1<=l<=r<=|s|,1<=k<=1e6)【类型】字符串操作水题【分析】首先k很大,但是显然可以使得k%=(r-l+1),提高运行效率。然后我们把右移溢出的k个字符先提取过来——for(int i=r-(k-1);i<=r;i++)tmp[++g]=s[i];然后再把右移无溢出的剩余字符提取过来——for(int i=l;i<=r-k;i++)tmp[++g]=s[i];接着还原即可——for(int i=1,j=l;i<=g;i++,j++)s[j]=tmp[i];【时间复杂度&&优化】O(m*|s|)*/
1 0
- 【Educational Codeforces Round 1B】【字符串平移 水题】Queries on a String 字符串平移水题
- Educational Codeforces Round 1 B. Queries on a String(字符串简单操作)
- Educational Codeforces Round 1 B. Queries on a String
- Educational Codeforces Round 1 B. Queries on a String
- Educational Codeforces Round 1 B.Queries on a String(模拟)
- 字符串平移
- Codeforces 598B Queries on a String 【水题】
- Educational Codeforces Round 16 B. Optimal Point on a Line
- Codeforces 598B Queries on a String 【思维】
- [杂题] Codeforces #598B. Queries on a String
- Educational Codeforces Round 16 B. Optimal Point on a Line (水题)
- Educational Codeforces Round 16 B. Optimal Point on a Line【水】
- Educational Codeforces Round 8 (A B C)
- Educational Codeforces Round 17 A+B
- Educational Codeforces Round 30(A+B)
- Educational Codeforces Round 31 A B C
- Educational Codeforces Round 32 A B C
- Educational Codeforces Round 4 A题 (python进行字符串的划分)
- LINUX下文件字符集编码查看与编码转换
- IE9 bug总
- iOS懒加载
- 动态监听网络状态
- 相关算子、卷积算子、边缘效应
- 【Educational Codeforces Round 1B】【字符串平移 水题】Queries on a String 字符串平移水题
- 深度学习基础1(神经网络)
- 边做边学Rust之变量绑定
- 浅谈JAVA二维数组
- [转]kindeditor编辑器的工具栏items的去和留
- jQuery之$.ajax()方法详解
- nyoj 187 快速查找素数【打表】
- 过来人经验!工作五年以上的UI设计师都在干什么?
- C# static const和readonly区别