首页 > 其他分享 >AtCoder Beginner Contest 242

AtCoder Beginner Contest 242

时间:2023-05-06 21:11:26浏览次数:39  
标签:AtCoder cnt cout Beginner int cin long 242 using

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;
}

标签:AtCoder,cnt,cout,Beginner,int,cin,long,242,using
From: https://www.cnblogs.com/PHarr/p/17378464.html

相关文章

  • AtCoder Beginner Contest 285(B,D,E,F)
    AtCoderBeginnerContest285(B,D,E,F)B(暴力,非二分)B这道题其实很简单,但是我在\(vp\)的过程,有了一个错误的认识,纠正一下那就是,我把这个当成了一个二分题,并且还有点坚定不移,后来细想,发现不对二分,适用于那种边界分明的那种题(左边一定是符合条件,右边一定符合条件,也可表达为线性......
  • [AtCoder-AT_ABC108_B]题解(C++)
    PartIPreface原题目(Luogu)原题目(AtCoder)PartIISketchPartIIIAnalysis观察这道题,我们很容易想到,必须推导出\(x1,y1,x2,y2\)与\(x3,y3,x4,y4\)之间的关系。我们观察下图。可以发现:\(\begin{aligned}\begin{cases}x3=x2-(y2-y1)\\y3=y2+(x2-......
  • AtCoder Regular Contest 131 E Christmas Wreath
    洛谷传送门AtCoder传送门不难猜想有解充要条件为\(n\ge5\)且\(\frac{n(n-1)}{2}\bmod3=0\)。发现如果钦定一个点的出边都为同一种颜色,那么条件\(2\)一定满足。那么题目等价于把\(\{0,1,...,n-1\}\)分成\(3\)组使得每组的和相等。这个东西可以随便dp做,也不......
  • AtCoder Regular Contest 131 D AtArcher
    洛谷传送门AtCoder传送门观察可以发现:使每支箭的距离都为\(D\)一定不劣;每支箭坐标一定为整数;设最左边的箭坐标为\(x\),那么\(x\)太小时可以把最左边的箭移到最右边,\(x\)太大时可以把最右边的箭移到最左边。计算可得\(x\)的最优取值范围为\(x\in[-\left\lfloor\fr......
  • 51nod 1242 斐波那契数列的第N项(矩阵快速幂)
    1242 斐波那契数列的第N项基准时间限制:1 秒空间限制:131072 KB分值: 0 难度:基础题 收藏 关注斐波那契数列的定义如下:F(0)=0F(1)=1F(n)=F(n-1)+F(n-2)(n>=2)(1,1,2......
  • AtCoder Regular Contest 128 E K Different Values
    洛谷传送门AtCoder传送门考虑判断有无解。把序列分成\(c=\left\lceil\frac{len}{k}\right\rceil\)段,则\(\foralla_i\lec\)且\(\sum\limits_{i=1}^n[a_i=c]\le((len-1)\bmodk)+1\)。必要性显然。充分性可以考虑直接构造,不难证明。考虑如何构造字典序最小......
  • AtCoder Regular Contest 134 D Concatenate Subsequences
    洛谷传送门AtCoder传送门我一年前甚至不会做/qd发现\(a_{x_1}\)为\(k=\min\limits_{i=1}^na_i\)时最优。然后开始分类讨论:如果\(\min\limits_{a_i=k}a_{i+n}\lek\),答案为\((k,\min\limits_{a_i=k}a_{i+n})\)。这是因为如果再选一个\(k\)肯定不优。否则......
  • AtCoder Beginner Contest 300
    A-N-choicequestion#include<bits/stdc++.h>usingnamespacestd;intread(){intx=0,f=1,ch=getchar();while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();if(ch=='-......
  • AtCoder Regular Contest 128 D Neq Neq
    洛谷传送门AtCoder传送门考虑把所有\(a_i=a_{i+1}\)的位置断开,分别计算然后把方案数乘起来。接下来的讨论假设\(a_i\nea_{i+1}\)。考虑一个dp,设\(f_i\)为\([1,i]\)最后剩下的集合的方案数。转移显然是\(f_i\getsf_i+f_j\),但是需要满足\((a_j,a_{j+1},...,......
  • AtCoder Beginner Contest 242(D,E)
    AtCoderBeginnerContest242(D,E)D(二叉树搜索)D题目大意就是首先给你一个字符串,代表\(S^0\),然后我们可以操作得到\(S^1,S^2\)等等我们可以知道\(S^i\)是拿\(S^(i-1)\)经过一系列替换而来的,因为这个字符串只有三种字符串,\(A,B,C\),这个替换方式就是把\(A\)替换成\(BC\),把\(B\)......