Codeforces Round #449 (Div. 2) (B、C)
程序员文章站
2022-03-11 12:04:05
...
B. Chtholly's request
http://codeforces.com/contest/897/problem/B
题目大意:
前k个偶数位的回文数之和
分析:
一个数对称之后就是偶数回文
AC代码:
#include <bits/stdc++.h>
#define gcd(a,b) __gcd(a,b)
#define mset(a,x) memset(a,x,sizeof(a))
#define FIN freopen("input","r",stdin)
#define FOUT freopen("output","w",stdout)
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const int MAX=1e5+10;
typedef long long LL;
const LL mod=1e9+7;
using namespace std;
LL cal(LL x){
LL ans=x;
while (x){
ans=ans*10+x%10;
x/=10;
}
return ans;
}
int main (){
LL k,p;
while (scanf ("%lld%lld",&k,&p)!=EOF){
LL res=0;
for (int i=1;i<=k;i++){
res=(res+cal(i))%p;
}
printf ("%lld\n",res);
}
return 0;
}
C. Nephren gives a riddle
http://codeforces.com/contest/897/problem/C
题目大意:
呃呃呃。。。。。。 题意不好说
分析:
事先计算 fi 的长度 k<LL 所以 n>53 以后不必再算下去 然后一层一层的找
AC代码:
#include <bits/stdc++.h>
#define gcd(a,b) __gcd(a,b)
#define mset(a,x) memset(a,x,sizeof(a))
#define FIN freopen("input","r",stdin)
#define FOUT freopen("output","w",stdout)
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const int MAX=1e5+10;
typedef long long LL;
const LL mod=1e9+7;
using namespace std;
string f0="What are you doing at the end of the world? Are you busy? Will you save us?";
string temp1="What are you doing while sending \"";
string temp2="\"? Are you busy? Will you send \"";
string temp3="\"?";
LL l0=f0.length();
LL l1=temp1.length();
LL l2=temp2.length();
LL l3=temp3.length();
LL countx[MAX];
void init(){
mset(countx,INF);
countx[0]=l0;
countx[1]=l1+l2+l3+countx[0]*2;
for (int i=2;countx[i-1]<=(LL)1e18;i++){
countx[i]=2*countx[i-1]+l1+l2+l3;
}
}
char dfs(int n,LL k){
if (n==0) return f0[k-1];
if(k<=l1) return temp1[k-1];// 34
k-=l1;
if(k<=countx[n-1]) return dfs(n-1,k);
k-=countx[n-1];
if(k<=l2) return temp2[k-1];// 32
k-=l2;
if(k<=countx[n-1]) return dfs(n-1,k);
k-=countx[n-1];
if (k<=l3) return temp3[k-1];// 2
}
int main (){
init();
int q;
scanf ("%d",&q);
LL n,k;
for (int i=0;i<q;i++){
scanf ("%lld%lld",&n,&k);
if (k>countx[n]&&n<=53) printf (".");
else printf ("%c",dfs(n,k));
}
putchar('\n');
return 0;
}
上一篇: Linux下文件去重
下一篇: 使用Tab键实现表格的跳转
推荐阅读
-
Codeforces Round #595 (Div. 3)D1D2 贪心 STL
-
Codeforces Round #655 (Div. 2) A. Omkar and Completion
-
Codeforces Round #487 (Div. 2)
-
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
-
Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs
-
Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing
-
Codeforces Round #659 (Div. 2) A. Common Prefixes(字符串,思维)
-
Codeforces Round #610 (Div. 2)
-
Codeforces Round #670 (Div. 2)
-
Codeforces Round #665 (Div. 2)