AtCoder Beginner Contest 242

A - T-shirt

#include <bits/stdc++.h>

using namespace std;

int32_t main(){
    double a , b , c , x;
	cin >> a >> b >> c >> x;
	if( x <= a ) cout << "1.000000000000";
	else if( x > b ) cout << "0.000000000000";
	else printf("%.10lf" , min( 1.0 , c / (b-a)  ) ); 
	return 0;
}

B - Minimize Ordering

#include <bits/stdc++.h>

using namespace std;


int32_t main(){
	ios::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr);
	string a;
	cin >> a;
	sort(a.begin(),a.end());
	cout << a;
	return 0;
}

C - 1111gal password

f[i][j]表示前i且以j结尾的方案数,f[i][j]=f[i-1][j-1]+f[i-1][j]+f[i-1][j+1]

滚动数组优化一下空间,特判一下边界即可

#include <bits/stdc++.h>

using namespace std;

const int mod = 998244353;

#define int long long

int32_t main(){
	ios::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr);
	int n;
	cin >> n;
	array<int,10> a , b;
	for( int i = 1 ; i <= 9 ; i ++ ) a[i] = 1;
	for( int j = 2 ; j <= n ; j ++ ){
		b[1] = a[1] + a[2] , b[9] = a[9] + a[8];
		for( int i = 2 ; i <= 8 ; i ++ )
			b[i] = a[i-1] + a[i] + a[i+1];
		a = b;
		for( auto & i : a ) i %= mod;
	}
	cout << accumulate(a.begin()+1,a.end(), 0ll ) % mod;
	return 0;
}

D - ABC Transform

首先字母的变换可以转化到0,1,2内。

对于\(S^i\)中的一位\(j\),如果当\(j\)是奇数,从\(S^{i-1}\)中$\left \lceil \frac j 2 \right \rceil \(位加 1 转移来,否则是从\)S^{i-1}\(中\)\left \lceil \frac j 2 \right \rceil $位加2转移来。

直到这个规律后,倒推出在最原始的位置,已经累计加了多少就可以知道所求的值。

#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main(){
	string s;
	cin >> s;
	int q;
	cin >> q;
	for( int cnt , t , k ; q ; q -- ){
		cin >> t >> k , cnt = t;
		for( ; t > 0 && k > 1 ; t -- ){
			if( k & 1 ) k ++;
			else cnt += 1;
			k >>= 1 , cnt %= 3;
		}
		k -- , cnt %= 3;
		cout << char((s[k]-'A'+cnt) % 3 + 'A') << "\n";
	}
	return 0;
}

E - (∀x∀)

其实可以把字符串当成 26 进制数。

首先我们考虑一个十进制数下的情况。

比如\(3456\),我们很荣幸想到构造方式是吧高位取出来\(34\),然后翻转拼接得到\(3443\),因为\(3443\le3456\),所以

\([0,34]\)中的数翻转拼接后都成立。还有一种情况是\(3412\),这样得到\(3443>3412\),所以\([0,33]\)中的数都满足。

得出这个结论后,实际就是把字符串翻转,然后比较一下,再做一个进制转换就好。

#include <bits/stdc++.h>

using namespace std;

const int mod = 998244353;

#define int long long

void solve(){
	int n , res = 0;
	string s , a , b;
	cin >> n >> s;
	a = b = s.substr(0 , (n+1)/2);
	reverse(b.begin() , b.end());
	if( n & 1 ) b.erase(b.begin());
	for( auto i : a ) res = (res * 26 + i - 'A') % mod;
	if( ( a + b ) <= s )  res = ( res + 1 ) % mod;
	cout << res << "\n";
	return ;
}

int32_t main(){
	ios::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr);
	int T;
	cin >> T;
	while(T--) solve();
	return 0;
}
posted @ 2023-05-06 21:01  PHarr  阅读(21)  评论(0编辑  收藏  举报