又掉分了0 0。
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] (froml-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.
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 string s after performing m operations described above.
3 1
ioi
1 1 i n
noi
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
gaaak
中规中矩的水题。
1 #include<bits/stdc++.h> 2 using namespace std; 3 char s[10000]; 4 int main() 5 { 6 int n,m,k,T,l,r; 7 char o,p; 8 scanf("%d%d",&n,&m); 9 scanf("%s",s); 10 for(int i=1;i<=m;i++) 11 { 12 scanf("%d%d %c %c",&l,&r,&o,&p); 13 for(int i=l-1;i<=r-1;i++) 14 if(s[i]==o) 15 s[i]=p; 16 } 17 printf("%s ",s); 18 return 0; 19 }
— 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 ispalindrome 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!
The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).
Output single integer — answer to the problem.
2 100
33
5 30
15
枚举下各位的情况就好了,最多12位的回文数。
1 #include<bits/stdc++.h> 2 #define clr(x) memset(x,0,sizeof(x)) 3 #define clr_1(x) memset(x,-1,sizeof(x)) 4 #define LL long long 5 #define INF 0x3f3f3f3f 6 using namespace std; 7 int n,k; 8 LL ans,mod; 9 void dfs(int lf,int sign,LL num) 10 { 11 if(k==0) 12 return ; 13 if(lf==0) 14 { 15 LL p=num; 16 while(p) 17 { 18 num*=10; 19 num+=p%10; 20 p/=10; 21 } 22 ans=(ans+num%mod)%mod; 23 k--; 24 return ; 25 } 26 if(sign) 27 for(int i=1;i<=9;i++) 28 dfs(lf-1,0,num*10+i); 29 else 30 for(int i=0;i<=9;i++) 31 dfs(lf-1,0,num*10+i); 32 return ; 33 } 34 int main() 35 { 36 scanf("%d%lld",&k,&mod); 37 ans=0; 38 for(int p=1;p<=6;p++) 39 { 40 if(k==0) 41 break; 42 dfs(p,1,0); 43 } 44 printf("%lld ",ans); 45 return 0; 46 }
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?
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).
One line containing q characters. The i-th character in it should be the answer for the i-th query.
3
1 1
1 2
1 111111111111
Wh.
5
0 69
1 194
1 139
0 47
1 66
abdef
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
Areyoubusy
最多到f50因此动态计算下fi的长度。这些都可以拿到dfs里去算,然后已经算出来长度的该跳过去的就跳过去。
1 #include<bits/stdc++.h> 2 #define clr(x) memset(x,0,sizeof(x)) 3 #define clr_1(x) memset(x,-1,sizeof(x)) 4 #define LL long long 5 #define INF 0x3f3f3f3f 6 using namespace std; 7 const int N=1e5+10; 8 string s0=" What are you doing at the end of the world? Are you busy? Will you save us?"; 9 string spre=" What are you doing while sending ""; 10 string son=" "? Are you busy? Will you send ""; 11 string slast=" "?"; 12 int n,m,t,p,now,s0size=s0.size()-1,spresize=spre.size()-1,sonsize=son.size()-1,slastsize=slast.size()-1; 13 LL k; 14 bool flag; 15 LL ss[N]; 16 int T; 17 void dfs(int n,LL pos) 18 { 19 if(flag) 20 return ; 21 if(n==0) 22 { 23 if(pos+s0size>=k) 24 { 25 printf("%c",s0[k-pos]); 26 flag=1; 27 return ; 28 } 29 else 30 return ; 31 } 32 if(pos+spresize>=k) 33 { 34 printf("%c",spre[k-pos]); 35 flag=1; 36 return ; 37 } 38 else 39 pos+=spresize; 40 if(ss[n-1]==0) 41 { 42 dfs(n-1,pos); 43 pos+=ss[n-1]; 44 } 45 else 46 { 47 if(pos+ss[n-1]>=k) 48 dfs(n-1,pos); 49 else 50 pos+=ss[n-1]; 51 } 52 if(flag) 53 return ; 54 if(pos+sonsize>=k) 55 { 56 printf("%c",son[k-pos]); 57 flag=1; 58 return ; 59 } 60 else 61 pos+=sonsize; 62 if(pos+ss[n-1]>=k) 63 dfs(n-1,pos); 64 else 65 pos+=ss[n-1]; 66 if(flag) 67 return ; 68 if(pos+slastsize>=k) 69 { 70 printf("%c",slast[k-pos]); 71 flag=1; 72 return ; 73 } 74 else 75 pos+=slastsize; 76 ss[n]=spresize+ss[n-1]+sonsize+ss[n-1]+slastsize; 77 return ; 78 } 79 int main() 80 { 81 ss[0]=s0size; 82 scanf("%d",&T); 83 while(T--) 84 { 85 scanf("%d%lld",&n,&k); 86 flag=0; 87 dfs(n,0); 88 if(!flag) 89 printf("."); 90 } 91 printf(" "); 92 return 0; 93 }
This is an interactive problem. Refer to the Interaction section below for better understanding.
Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight.
Initially, Ithea puts n clear sheets of paper in a line. They are numbered from 1 to n from left to right.
This game will go on for m rounds. In each round, Ithea will give Chtholly an integer between 1 and c, and Chtholly needs to choose one of the sheets to write down this number (if there is already a number before, she will erase the original one and replace it with the new one).
Chtholly wins if, at any time, all the sheets are filled with a number and the n numbers are in non-decreasing order looking from left to right from sheet 1 to sheet n, and if after m rounds she still doesn't win, she loses the game.
Chtholly really wants to win the game as she wants to cook something for Willem. But she doesn't know how to win the game. So Chtholly finds you, and your task is to write a program to receive numbers that Ithea gives Chtholly and help her make the decision on which sheet of paper write this number.
The first line contains 3 integers n, m and c (, means rounded up) — the number of sheets, the number of rounds and the largest possible number Ithea can give to Chtholly respectively. The remaining parts of input are given throughout the interaction process.
In each round, your program needs to read one line containing a single integer pi (1 ≤ pi ≤ c), indicating the number given to Chtholly.
Your program should then output a line containing an integer between 1 and n, indicating the number of sheet to write down this number in.
After outputting each line, don't forget to flush the output. For example:
- fflush(stdout) in C/C++;
- System.out.flush() in Java;
- sys.stdout.flush() in Python;
- flush(output) in Pascal;
- See the documentation for other languages.
If Chtholly wins at the end of a round, no more input will become available and your program should terminate normally. It can be shown that under the constraints, it's always possible for Chtholly to win the game.
2 4 4
2
1
3
1
2
2
很有意思的是,m≥n*[c/2]就能保证形成非严格递增的序列,我们可以从这里切入。
那么我们从[c/2]入手。把新加入的数分为小于等于[c/2]和大于[c/2]两类。如果初始序列前半部分(长度不定)都是小于等于[c/2],后半部分都是大于[c/2],那么对于前半部分每个数字做最多[c/2]-1次向更小的数替换,后半部分做最多c-[c/2]-1次向更大数的替换,就能得到要求序列。那么总次数最多就是题目中的n*[c/2]了,也就是在m次能得到答案。那么我有一个大胆的想法:遇到小于等于[c/2],从头到尾找第一个空位置或者大于它的数替换,大于[c/2],从尾到头找第一个空位置或小于它的数替换,能达到上述的效果。
1 #include<bits/stdc++.h> 2 #define clr(x) memset(x,0,sizeof(x)) 3 #define clr_1(x) memset(x,-1,sizeof(x)) 4 #define mod 1000000007 5 #define LL long long 6 #define INF 0x3f3f3f3f 7 using namespace std; 8 const int N=1e4+10; 9 int a[N]; 10 bool flag; 11 int main() 12 { 13 int n,m,p,now,c; 14 scanf("%d%d%d",&n,&m,&c); 15 for(int i=1;i<=m;i++) 16 { 17 scanf("%d",&p); 18 if(p*2<=c) 19 { 20 for(int j=1;j<=n;j++) 21 if(a[j]==0 || a[j]>p) 22 { 23 a[j]=p; 24 printf("%d ",j); 25 fflush(stdout); 26 break; 27 } 28 } 29 else 30 { 31 for(int j=n;j>=1;j--) 32 if(a[j]==0 || a[j]<p) 33 { 34 a[j]=p; 35 printf("%d ",j); 36 fflush(stdout); 37 break; 38 } 39 } 40 flag=1; 41 for(int i=2;i<=n;i++) 42 if(a[i]==0 || a[i]<a[i-1]) 43 { 44 flag=0; 45 break; 46 } 47 if(a[1]==0) flag=0; 48 if(flag) 49 return 0; 50 } 51 }