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

Atcoder Beginner Contest 242

时间:2022-12-28 09:56:28浏览次数:37  
标签:Atcoder main 题意 Beginner int s1 242 include dp

由于我8点半才下课,我只好晚半个小时再打,这次还行,排名3042

五道题,秒了前三道,第四道不会,第五道想出正解,结果一直不对,比完后看了一下大佬的代码恍然大悟,但是比赛早已结束.....

A: T-shirt

题意:

All participants who ranked A-th or higher get a T-shirt.

Additionally, from the participants who ranked between (A+1)-th and B-th (inclusive), C participants chosen uniformly at random get a T-shirt

我就不翻译了,很简单。

Code

#include<iostream>
#include<cstdio>
using namespace std;
int a, b, c, x;
int main(){
	cin >> a >> b >> c >> x;
	double ans;
	if(x <= a){
		ans = 1.0;
	}
	else if(x > b){
		ans = 0;
	}
	else{
		ans = 1.0 * c / (b - a);
	}
	printf("%.7lf", ans);
	return 0; 
}

B:Minimize Ordering

题意:给一个字符串升序排序

啊这。。。。。。

我觉得应该放在A

Code

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
string s;
int main(){
	cin >> s;
	sort(s.begin(), s.end());
	cout << s;
	return 0; 
}

C:1111gal password

题意:询问有多少个N位正整数,每一位上为1~9,且相邻两位相差不超过一

总算遇到递推了,恰好前几天做了好多USACO的DP题。

思路很简单,dp[i][j]为i长度以j结尾的方法数,状态转移方程:

dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j + 1] + dp[i - 1][j]

That's all

Code

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
long long dp[1000005][10] = {0};
const int mod = 998244353;
int main(){
	cin >> n;
	for(int i = 1; i <= 9; i++)
		dp[1][i] = 1;
	for(int i = 2; i <= n; i++){
		dp[i][1] = dp[i - 1][1] + dp[i - 1][2];
		dp[i][1] %= mod;
		for(int j = 2; j <= 8; j++)
			dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j + 1] + dp[i - 1][j], dp[i][j] %= mod;
		dp[i][9] = dp[i - 1][9] + dp[i - 1][8];
		dp[i][9] %= mod;
	}
	long long ans = 0;
	for(int i = 1; i <= 9; i++)
		ans += dp[n][i], ans %= mod;
	cout << ans;
	return 0; 
}

D:ABC Transform

看了一眼数据范围10^18,就没心思读题了……

E: (∀x∀)

题意:给一个n长度的字符串s,求有多少个字符串t,其长度为s,且为回文串,同时字典序小于等于s

我第一次想到了第五题的做法!!! 虽然没做对

首先判断奇偶

我们可以依次处理1~n/2,每次算出这一位之前都不变,这一位比原来小的情况数,

最后判断一下1~n /2都相同时的回文串是否比原来小

我是这样写的:

if(a[n / 2] <= a[n / 2 + 1])
   ans++;
ans %= mod;

WA了6个点QWQ。。。。

实际要考虑后面的请况,应该这么写:

string s1 = s;
for(int i = 0; i < n / 2; i++)
	s1[n - i - 1] = s1[i];
if(s1 <= s)
	ans = (ans + 1) % mod;

考后代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
string s;
int t, n;
const int mod = 998244353;
#define ll long long
ll p26[1000005];
int a[1000005] = {0};
string s1;
int main(){
	//freopen("p.in", "r", stdin);
	cin >> t;
	p26[0] = 1;
	for(int i = 1; i <= 500005; i++)
		p26[i] = 1ll * p26[i - 1] * 26, p26[i] %= mod;
	for(int abc = 1; abc <= t; abc++){
	//	memset(a, 0, sizeof a);
		scanf("%d", &n);
		ll ans = 0;
		string s;
		cin >> s;
		s1 = s;
		for(int i = 1; i <= n; i++){
			a[i] = s[i - 1] - 'A' + 1;
		}
		if(n % 2 == 0){
			for(int i = 1; i <= n / 2; i++){
				ans += 1ll * (a[i] - 1) * p26[n / 2 - i];
				ans %= mod;
			}
			for(int i = 0; i < n / 2; i++)
				s1[n - i - 1] = s1[i];
			if(s1 <= s)
				ans = (ans + 1) % mod;
		}
		else{
			for(int i = 1; i <= n / 2 + 1; i++){
				ans += 1ll * (a[i] - 1) * p26[n / 2 - i + 1];
				ans %= mod;
			}
			for(int i = 0; i < n / 2; i++)
				s1[n - i - 1] = s1[i];
			if(s1 <= s)
				ans = (ans + 1) % mod;
		}
		printf("%lld\n", ans);
	}
	return 0; 
}

总结:都还好,注意细节!!!

今天我们学贪心,还是很有难度的……

That's all

标签:Atcoder,main,题意,Beginner,int,s1,242,include,dp
From: https://www.cnblogs.com/rlc202204/p/17009467.html

相关文章

  • AtCoder Beginner Contest 283
    《E-Don'tIsolateElements》dp   刚开始拿到这道题时,我总是在想:第一行翻不翻转对下面情况的影响,在什么情况下要反转,等一系列情况最后我发现:这些情况不如我可......
  • Atcoder Beginner Contest ABC 283 Ex Popcount Sum 题解 (类欧几里得算法)
    题目链接令\(p=\lfloor\frac{n-r}m\rfloor\),则我们其实是要对所有\(0\lei\le29\)求\(\sum_{j=0}^p(\lfloor\frac{mj+r}{2^i}\rfloormod\2)\)。右边那个东西如果没......
  • AtCoder Grand Contest 060(持续更新)
    Preface那一天,闪总终于想起了被ACG支配的恐惧……只能说还好Rating不够,这场Unrated打的,写了个A然后B一直挂(一个细节没想到),C数数又数不来90min后光速跑路推Gal去了A-......
  • 【SDOI2011】【BZOJ2242】计算器
    Description你被要求设计一个计算器完成以下三项任务:1、给定y、z、p,计算y^zmodp的值;2、给定y、z、p,计算满足xy≡z(modp)的最小非负整数;3、给定y、z......
  • 242.一个简单的整数问题
    传送门题目大意给定长度为\(N\)的数列\(A\),然后输入\(M\)行操作指令。第一类指令形如Clrd,表示把数列中第\(l\simr\)个数都加\(d\)。第二类指令形如Qx,......
  • AtCoder Beginner Contest 283(A~F)
    Aa,b=map(int,input().split())print(pow(a,b))Bn=int(input())a=list(map(int,input().split()))q=int(input())foriinrange(q):op=list(map(int,input()......
  • 「杂题乱写」AtCoderDP26 题
    「杂题乱写」AtCoderDP26题\(\text{AtCoderDP26}\)题题单。前言最近听说\(\text{AtCoder}\)上有个\(\text{DP26}\)题挺好的,于是向@\(\text{SoyTony}\)要了题单......
  • AtCoder Beginner Contest 283
    A-Power(abc283a)题目大意给定\(A,B\),输出\(A^B\)解题思路数不大,暴力即可。数大了可用快速幂。神奇的代码#include<bits/stdc++.h>usingnamespacestd;us......
  • atcoder
    AGC001D题目大意:有一个长度为\(m\)的序列\(a\),它的和为\(n\),需要将\(a\)重排,并构造一个任意长度但和为\(n\)的序列\(b\),使得对任意长度为\(n\)的字符串,如果......
  • [翻译]写给初学者的源代码安装指南Beginner's Guide to Installing from Source
    写给初学者的源代码安装指南引入本文档面向希望直接从原始作者处安装软件的开源操作系统用户,而不是仅依赖其操作系统提供的软件(和版本)。它是为那些不熟悉以源代码形式下......