Codeforces Round #449 (Div. 2)-897A.Scarborough Fair(字符替换水题) 897B.Chtholly's request(处理前一半) 897C.Nephren gives a riddle(递归)
2017-12-06 21:31
579 查看
A. Scarborough Fair
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Are you going to Scarborough Fair?
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Although the girl wants to help, Willem insists on doing it by himself.
Grick gave Willem a string of length n.
Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.
Grick wants to know the final string after all the m operations.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100).
The second line contains a string s of length n, consisting of lowercase English letters.
Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
Output
Output string s after performing m operations described above.
Examples
input
output
input
output
Note
For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak.
题意好理解,直接代码:
B. Chtholly's request
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
— Thanks a lot for today.
— I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.
Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.
Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!
Input
The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).
Output
Output single integer — answer to the problem.
Examples
input
output
input
output
Note
In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example,
![](http://codeforces.com/predownloaded/54/c6/54c6d0dbabe436ef632b6c37073828e25f8d59de.png)
.
题意就是回文,而且回文的长度是偶数,将前k个符合条件的加起来然后%p。
直接将这个回文分成两半,将前一半的反转一下就是后面一半的。
代码:
C. Nephren gives a riddle
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
What are you doing at the end of the world? Are you busy? Will you save us?
![](http://codeforces.com/predownloaded/03/19/03197c7c57d21a9b79bfe7685133f9bbc92303ed.png)
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... ∞.
f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about it, so she defines fi = "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.
For example, f1 is
"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.
It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.
Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).
Can you answer her queries?
Input
The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.
Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).
Output
One line containing q characters. The i-th character in it should be the answer for the i-th query.
Examples
input
output
input
output
input
output
Note
For the first two examples, refer to f0 and f1 given in the legend.
题意看了好久,才明白什么意思。
除了f0 ,其他的都是在固定的那两句话和问号中插入上一个f的内容。就是假设a b c ,在a和b中间和b和c中间插入上一个f的内容。
这个题先处理一下1e5的数据的长度。首先先初始化,初始化的数组存的长度只要大于1e5就可以,因为题目说f的长度大于1e5就输出.(输出点.)
为什么一定要初始化呢,假设是第53个f的长度大于1e5,53之后的f的长度都应该是大于1e5的,但是处理的时候53以后的已经跳出了。
所以在一开始赋初值的的时候就先把长度赋值大于1e5就可以。
我写的1e5+1,哈哈哈。
然后就是递归处理,依次判断然后减去就可以。
对于问号的处理可以先递归模拟一下前几个f就可以。
其他的没什么坑了。
直接代码:
cf的测评姬小姐姐最近可能心情不好,打cf的时候测题好慢。
加油啊,简直要菜哭了。
咸鱼加油,好好对待我的id,ZERO。
向学长学习。
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Are you going to Scarborough Fair?
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Although the girl wants to help, Willem insists on doing it by himself.
Grick gave Willem a string of length n.
Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.
Grick wants to know the final string after all the m operations.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100).
The second line contains a string s of length n, consisting of lowercase English letters.
Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
Output
Output string s after performing m operations described above.
Examples
input
3 1 ioi 1 1 i n
output
noi
input
5 3 wxhak 3 3 h x 1 5 x a 1 3 w g
output
gaaak
Note
For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak.
题意好理解,直接代码:
1 //A. Scarborough Fair 字符更换 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 #include<cmath> 6 #include<iostream> 7 using namespace std; 8 const int N=1e5+10; 9 char s ; 10 int main(){ 11 int n,m; 12 while(~scanf("%d%d",&n,&m)){ 13 scanf("%s",s); 14 int len=strlen(s); 15 while(m--){ 16 char a,b; 17 int l,r; 18 cin>>l>>r>>a>>b; 19 for(int i=l-1;i<r;i++){ 20 if(s[i]==a)s[i]=b; 21 } 22 } 23 printf("%s\n",s); 24 } 25 return 0; 26 }
B. Chtholly's request
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
— Thanks a lot for today.
— I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.
Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.
Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!
Input
The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).
Output
Output single integer — answer to the problem.
Examples
input
2 100
output
33
input
5 30
output
15
Note
In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example,
![](http://codeforces.com/predownloaded/54/c6/54c6d0dbabe436ef632b6c37073828e25f8d59de.png)
.
题意就是回文,而且回文的长度是偶数,将前k个符合条件的加起来然后%p。
直接将这个回文分成两半,将前一半的反转一下就是后面一半的。
代码:
1 //B.Chtholly's request 处理前一半 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 using namespace std; 8 typedef long long ll; 9 const int N=1e5+10; 10 int h; 11 ll s ; 12 int zz(int n){ 13 int a[10]; 14 while(n!=0){ 15 a[h++]=n%10; 16 n/=10; 17 } 18 int ans=0; 19 for(int i=0;i<h;i++){ 20 ans=ans*10+a[i]; 21 } 22 return ans; 23 } 24 int main(){ 25 int k,p; 26 ll ans; 27 while(~scanf("%d%d",&k,&p)){ 28 for(int i=1;i<=k;i++){ 29 h=0; 30 int x=zz(i); 31 s[i]=i*pow(10,h)+x; 32 } 33 ans=0; 34 for(int i=1;i<=k;i++){ 35 ans=(ans+s[i])%p; 36 } 37 printf("%lld\n",ans); 38 } 39 return 0; 40 }
C. Nephren gives a riddle
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
What are you doing at the end of the world? Are you busy? Will you save us?
![](http://codeforces.com/predownloaded/03/19/03197c7c57d21a9b79bfe7685133f9bbc92303ed.png)
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... ∞.
f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about it, so she defines fi = "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.
For example, f1 is
"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.
It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.
Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).
Can you answer her queries?
Input
The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.
Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).
Output
One line containing q characters. The i-th character in it should be the answer for the i-th query.
Examples
input
3 1 1 1 2 1 111111111111
output
Wh.
input
5 0 69 1 194 1 139 0 47 1 66
output
abdef
input
10 4 1825 3 75 3 530 4 1829 4 1651 3 187 4 584 4 255 4 774 2 474
output
Areyoubusy
Note
For the first two examples, refer to f0 and f1 given in the legend.
题意看了好久,才明白什么意思。
除了f0 ,其他的都是在固定的那两句话和问号中插入上一个f的内容。就是假设a b c ,在a和b中间和b和c中间插入上一个f的内容。
这个题先处理一下1e5的数据的长度。首先先初始化,初始化的数组存的长度只要大于1e5就可以,因为题目说f的长度大于1e5就输出.(输出点.)
为什么一定要初始化呢,假设是第53个f的长度大于1e5,53之后的f的长度都应该是大于1e5的,但是处理的时候53以后的已经跳出了。
所以在一开始赋初值的的时候就先把长度赋值大于1e5就可以。
我写的1e5+1,哈哈哈。
然后就是递归处理,依次判断然后减去就可以。
对于问号的处理可以先递归模拟一下前几个f就可以。
其他的没什么坑了。
直接代码:
1 //C.Sorting Railway Cars 递归 2 #include<iostream> 3 #include<cstring> 4 #include<cstdio> 5 #include<cmath> 6 #include<algorithm> 7 using namespace std; 8 typedef long long ll; 9 const int N=1e5+10; 10 char a0[]={"What are you doing at the end of the world? Are you busy? Will you save us?"}; 11 char a1[]={"What are you doing while sending \""}; 12 char a2[]={"\"? Are you busy? Will you send \""}; 13 char a3[]={"\"?"}; 14 ll len ; 15 ll l0,l1,l2,l3; 16 char digui(ll n,ll k){ 17 if(n==0)return a0[k-1]; 18 if(k<=l1)return a1[k-1];k-=l1; 19 if(k<=len[n-1])return digui(n-1,k);k-=len[n-1]; 20 if(k<=l2)return a2[k-1];k-=l2; 21 if(k<=len[n-1])return digui(n-1,k);k-=len[n-1]; 22 return a3[k-1]; 23 } 24 int main(){ 25 l0=strlen(a0); 26 l1=strlen(a1); 27 l2=strlen(a2); 28 l3=strlen(a3); 29 len[0]=l0; 30 for(ll i=1;i<=1e5;i++) 31 len[i]=1e18+1; 32 for(int i=1;i<=1e5;i++){ 33 len[i]=len[i-1]*2+l1+l2+l3; 34 if(len[i]>1e18)break; 35 } 36 char ans ; 37 ll q,n,k; 38 while(~scanf("%lld",&q)){ 39 memset(ans,0,sizeof(ans)); 40 ll h=0; 41 while(q--){ 42 scanf("%lld%lld",&n,&k); 43 if(k>len )ans[h++]='.'; 44 else ans[h++]=digui(n,k); 45 } 46 for(int i=0;i<h;i++) 47 cout<<ans[i]; 48 } 49 return 0; 50 }
cf的测评姬小姐姐最近可能心情不好,打cf的时候测题好慢。
加油啊,简直要菜哭了。
咸鱼加油,好好对待我的id,ZERO。
向学长学习。
相关文章推荐
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- codeforces 897C Nephren gives a riddle 递归
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- 【codeforces 897C】Nephren gives a riddle (递归)
- code force 449 div2 C. Nephren gives a riddle
- codeforces 897C Nephren gives a riddle
- [Easy]CodeForces - 897C Nephren gives a riddle | dfs + 特判
- Codeforces Round #449 (Div. 2). C. Nephren gives a riddle