Description
Solution
直接用加法减法+模即可。
复杂度:O(n)
这么水的题我写来干嘛
Code
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=100500;
int n,m,ans;
int a[N];
int nm[N][15];
int main()
{
freopen("toy.in","r",stdin);
freopen("toy.out","w",stdout);
int q,w;char ch;
scanf("%d%d",&n,&m);
fo(i,0,n-1)
{
scanf("%d",&q);
a[i]=1;if(q)a[i]=-1;
ch=' ';
for(ch=' ';ch<'a'||ch>'z';ch=getchar());
while(ch<='z'&&ch>='a')nm[i][++nm[i][0]]=ch,ch=getchar();
}
ans=0;
fo(i,1,m)
{
scanf("%d%d",&q,&w);
if(q)q=1;else q=-1;
ans=(ans+q*a[ans]*w+n)%n;
}
fo(i,1,nm[ans][0])printf("%c",nm[ans][i]);
return 0;
}
本文介绍了一种基于模运算的简单算法实现方案,通过加法、减法及模运算完成特定问题的解决,并实现了O(n)的时间复杂度。文中提供了一个C++代码示例,用于演示如何读取输入数据并进行相应的计算。
406

被折叠的 条评论
为什么被折叠?



