欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Codeforces Round #449 (Div. 2) A-C题解

程序员文章站 2022-03-11 12:03:29
...

又一次涨分,虽然上次也在涨分,但没心情写博客,就做出一个题,补题体验感也不好,这次C题看了一个半小时没做出来,真是水的可以。

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] (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.

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 ≤ nc1, 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.


题意通俗易懂,就是找到一个区间,找到相同的字符,就换成另一个字符,模拟即可。


代码实现:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
string map;

int main()
{
	int n,m,i,j,k,x,y;
	char c1,c2;
	cin>>n>>m;
	cin>>map;
	for(j=0;j<m;j++)
	{
		cin>>x>>y>>c1>>c2;
		for(i=x-1;i<=y-1&&map[i];i++)
		{
			if(map[i]==c1)
			map[i]=c2;
		}
	}	
	cout<<map<<endl;
}

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 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!

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, Codeforces Round #449 (Div. 2) A-C题解.


一道思维题,也没什么坑,就是偶数位的回文串,从小到大,前k个的和是多少。
既然是偶数位,还是回文串,直接枚举1到100000然后倒置拼接就ok。

代码实现:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
ll ans[maxn];

int main()
{
	int n,i,j,k=0;
	for(i=1;i<=100005;i++)
	{
		char map[100];
		int temp=i,len=0,j=0;
		while(temp)
		{
			map[j++]=temp%10;
			temp/=10;
		}
		ans[i]=i;
		for(int l=0;l<j;l++)
		{
			ans[i]=ans[i]*10+(map[l]);
		}
	}
	int p;
	cin>>n>>p;
	ll ans1=0;
	for(i=1;i<=n;i++)
	ans1=(ans1+ans[i])%p;
	
	cout<<ans1<<endl;
	return 0;
}
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?

Codeforces Round #449 (Div. 2) A-C题解

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.


稍微有点难懂英文的题,但说明的很详细,就是简单的dfs,打表发现第53项之后字符串会长于1e18,所以后面的长度直接赋值为第53项就好。

代码实现:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
char *f0="What are you doing at the end of the world? Are you busy? Will you save us?";
char *a="What are you doing while sending \"";
char *b="\"? Are you busy? Will you send \"";
char *c="\"?";
ll dp[100005];

char dfs(ll n,ll k)
{
	if(k>dp[n])
	return '.';
	
	if(n==0)
	return f0[k-1];
	
	if(k<=34)
	return a[k-1];
	k-=strlen(a);
	
	if(k<=dp[n-1])
	return dfs(n-1,k);
	k-=dp[n-1];
	
	if(k<=strlen(b))
	return b[k-1];
	k-=strlen(b);
	
	if(k<=dp[n-1])
	return dfs(n-1,k);
    k-=dp[n-1];
    
    if(k<=2)
	return c[k-1];
}

int main()
{
	int i,j,t;
	ll n,k;
	dp[0]=75;dp[1]=218;
	for(i=2;i<=54;i++)
	dp[i]=dp[i-1]*2+68;
	for(i=55;i<=100000;i++)
	dp[i]=dp[53];
	scanf("%d",&t);
	while(t--)
	{
		cin>>n>>k;
		cout<<dfs(n,k);
	}
	return 0;
}


相关标签: codeforces