cf又是卡在D上了呢
出题人热爱珂学.jpg
题意:给你一个字符串 m个操作 每次把[l,r]里面的字符c1换成字符c2
数据范围不大直接暴力
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char A[110];
int main(){
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
int n,m;
scanf("%d %d",&n,&m);
scanf("%s",A+1);
int l,r;
char a,b;
for(int i=1;i<=m;i++){
scanf("%d %d",&l,&r);
cin>>a>>b;
for(int j=l;j<=r;j++)
if(A[j]==a)
A[j]=b;
}
for(int i=1;i<=n;i++)
printf("%c",A[i]);
return 0;
}
B题
询问前k个回文且长度为偶的数之和模p的值
容易想到这样的数其实就是正常的1....k作为回文串左半边再对他进行回文操作
时间复杂度O(k)
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
long long base[30];
int A[30];
inline int tran(int x){
int num=0;
while(x){
A[++num]=x%10;
x/=10;
}
int tmp=0,td=1;
for(int i=num;i>=1;i--){
tmp+=td*A[i];
td*=10;
}
return tmp;
}
inline int pl(int x){
int num=0;
while(x){
num++;
x/=10;
}
return num;
}
int main(){
//("a.in","r",stdin);
//freopen("a.out","w",stdout);
int n,k;
scanf("%d %d",&n,&k);
long long ans=0;
base[0]=1;
for(int i=1;i<=10;i++)
base[i]=base[i-1]*10;
for(int i=1;i<=n;i++){
ans+=(long long)base[pl(i)]*i;
ans%=k;
ans+=tran(i);
ans%=k;
}
printf("%lld\n",ans);
return 0;
}
C题
递归定义一段字符串
f[i]=a+f[i-1]+b+f[i-1]+c
f[0]=d;
询问第k个串的第m个字符
询问数<=10
直接暴力递归 每层分5类情况讨论
f[53]长度就大于最大的查询了
那么对于所有k>53直接分2类情况讨论 属于a中或属于f[i-1]中
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=100000+10;
char A[80]={" What are you doing at the end of the world? Are you busy? Will you save us?"};
char B[40]={" What are you doing while sending \""};
char C[40]={" \"? Are you busy? Will you send \""};
char D[40]={" \"?"};
long long len[maxn];
inline char work(int x,long long k){
if(x>53){
if(k<=34)
return B[k];
else return work(x-1,k-34);
}
if(!x)
return A[k];
else if(k<=34)
return B[k];
else if(k>34&&k<=34+len[x-1])
return work(x-1,k-34);
else if(k>34+len[x-1]&&k<=34+len[x-1]+32)
return C[k-34-len[x-1]];
else if(k>34+len[x-1]+32&&k<=34+len[x-1]+32+len[x-1])
return work(x-1,k-34-len[x-1]-32);
else return D[k-34-len[x-1]-32-len[x-1]];
}
int main(){
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
//printf("%d\n%d\n%d\n",strlen(A+1),strlen(B+1),strlen(C+1));
//cout<<A[1]<<endl;
len[0]=75;
for(int i=1;i<=100000;i++)
len[i]=2*len[i-1]+34+32+2;
int q;
scanf("%d",&q);
int n;long long k;
while(q--){
scanf("%d %lld",&n,&k);
if(k>len[n]&&n<=53)
printf(".");
else printf("%c",work(n,k));
}
return 0;
}