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

Codeforces Round #449 (Div. 2)

程序员文章站 2024-02-24 12:16:17
...

A

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e6 + 10;
const int INF = 1e9 + 10;
char st[105];

int main(){
	int n, m;	scanf("%d%d", &n, &m);
	scanf("%s", st + 1);
	while(m--) {
		int l, r;
		char x, y;
		scanf("%d%d %c %c", &l, &r, &x, &y);
		getchar();
		for(int i = l; i <= r; ++i) {
			if(st[i] == x)	st[i] = y;
		}
	}
	puts(st + 1);
	return 0;
}


B

思路:可以发现这种回文的大小就是 11,22,33...1001,1111,1221,观察可以发现1,2,3...10,11,12

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e6 + 10;
const int INF = 1e9 + 10;
LL k, m;
LL getNum(LL x) {
	string ans = "";
	while(x > 0) {
		ans += (x % 10 + '0');
		x /= 10;
	}
	string cns = ans;
	reverse(ans.begin(), ans.end());
	ans += cns;
	LL tmp = 0;
	for(int i = 0; i < ans.size(); ++i) {
		tmp = (tmp * 10LL) + ans[i] - '0';
	}
	return tmp;
}

int main(){
	scanf("%lld%lld", &k, &m);
	LL ans = 0;
	for(int i = 1; i <= k; ++i) {
		ans = (ans + getNum(i)) % m;
	}
	printf("%lld\n", ans);
	return 0;
}


C

思路:一个递归的思维题,看代码理解吧

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const LL INF = 1e18 + 1;
string s1 = "What are you doing at the end of the world? Are you busy? Will you save us?";
string s2 = "What are you doing while sending \"";
string s3 = "\"? Are you busy? Will you send \"";
string s4 = "\"?";
int len1, len2, len3, len4;
LL f[qq];
void dfs(int n, LL k) {
	if(n == 0) {
		cout << s1[k - 1];
	} else if(k <= len2) {
		cout << s2[k - 1];
	} else if(k <= len2 + f[n - 1]) {
		k -= len2;
		dfs(n - 1, k);
	} else if(k <= len2 + f[n - 1] + len3) {
		k -= len2 + f[n - 1];
		cout << s3[k - 1];
	} else if(k <= len2 + f[n - 1] + len3 + f[n - 1]) {
		k -= len2 + f[n - 1] + len3;
		dfs(n - 1, k);
	} else {
		k -= len2 + f[n - 1] + len3 + f[n - 1];
		cout << s4[k - 1];
	}
}

int main() {
	len1 = s1.size(), len2 = s2.size(), len3 = s3.size(), len4 = s4.size();
	f[0] = len1;
	for(int i = 1; i < qq; ++i) {
		f[i] = min(len2 + f[i - 1] + len3 + f[i - 1] + len4, INF);
	}
	int q;	scanf("%d", &q);
	LL n, k;
	while(q--) {
		scanf("%lld%lld", &n, &k);
		if(k > f[n]) {
			cout << "." ;
		} else {
			dfs(n, k) ;
		}
	}
	cout << endl;
	return 0;
}