AtCoder ABC214 简单题解

ABC编程竞赛解析与算法实现
这篇博客详细解析了ABC编程竞赛中多个问题的解题思路和AC代码,包括签到水题、三元组计数、鹤的宝石传递和最短路径问题等。通过这些题目,展示了如何运用不同的算法解决实际编程问题。

好久没更新了。今天参加了一下 ABC,防止抑郁。

A - New Generation ABC

链接

https://atcoder.jp/contests/abc214/tasks/abc214_a

题解

签到水题。
给 ABC 竞赛的编号,问对应的竞赛有几个问题。

AC 代码

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLL;

const LL INF=4e18;
const int MAXN=1e6+10;

int main() {
#if 1
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#endif
	//freopen("00.in", "r", stdin);
	//freopen("00.out", "w", stdout);
	LL n;
	cin>>n;
	if (n<=125) {
		cout<<"4\n";
	} else if (n<=211) {
		cout<<"6\n";
	} else {
		cout<<"8\n";
	}
	
	return 0;
}

B - How many?

链接

https://atcoder.jp/contests/abc214/tasks/abc214_b

题解

a + b + c ≤ S a+b+c \leq S a+b+cS 同时 a ∗ b ∗ c ≤ T a*b*c \leq T abcT 的三元组 ( a ,   b ,   c ) (a,\ b,\ c) (a, b, c) 的个数。但是本题的数据范围是 0 ≤ S ≤ 100 ,   0 ≤ T ≤ 10000 0 \leq S \leq 100,\ 0 \leq T \leq 10000 0S100, 0T10000
因此,我们知道 0 ≤ a ,   b ,   c ≤ 100 0 \leq a,\ b,\ c \leq 100 0a, b, c100。那么我们直接暴力枚举即可。

AC 代码

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLL;

const LL INF=4e18;
const int MAXN=1e6+10;

int main() {
#if 1
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#endif
	//freopen("00.in", "r", stdin);
	//freopen("00.out", "w", stdout);
	LL s,t;
	cin>>s>>t;
	
	LL ans=0;
	for (LL a=0; a<=100; a++) {
		for (LL b=0; b<=100; b++) {
			for (LL c=0; c<=100;c++) {
				if (a+b+c<=s && a*b*c<=t) {
					ans++;
				}
			}
		}
	}
	cout<<ans<<"\n";
	
	return 0;
}

C - Distribution

链接

https://atcoder.jp/contests/abc214/tasks/abc214_c

题解

N N N 只鹤逆时针围成圈,高桥在 T i T_i Ti 的时间给第 i i i 只鹤一个宝石,这只鹤过了 S i S_i Si 的时间后,将宝石传递给下一只鹤。问每只鹤第一次拿到宝石的时间。
根据题意,我们知道第一次拿到宝石有两种可能:
1、高桥给的。对应的时间点为 T i T_i Ti
2、上只鹤传递过来。对应的时间为 T i − 1 + S i − 1 T_{i-1}+S_{i-1} Ti1+Si1
因此问题就是要确认最小的 T i T_i Ti 是哪个,然后我们从这个 i i i 开始递推即可。

AC 代码

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLL;

const LL INF=4e18;
const int MAXN=2e5+10;
LL s[MAXN];
LL t[MAXN];
LL ans[MAXN]; 
 
int main() {
#if 0
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#endif
	//freopen("00.in", "r", stdin);
	//freopen("00.out", "w", stdout);
	LL n;
	cin>>n;
	for (LL i=1; i<=n; i++) {
		cin>>s[i];
	} 
	for (LL i=1; i<=n; i++) {
		cin>>t[i];
	}
	
	//第i个snuke拿到gem有两个可能
	//高桥给
	//上面的sunke给。
	LL mint=4e18;
	LL st;
	//找到第一个开始的时间 
	for (LL i=1; i<=n; i++) {
		if (mint>t[i]) {
			mint=t[i];
			st=i;
		}
	}
	ans[st]=t[st];
	for (LL i=st; i<=st+n-1; i++) {
		LL now=i>n?i-n:i;//现在的编号 
		LL nxt=now+1;//下一个编号
		if (nxt>n) {
			nxt-=n;
		} 
		ans[nxt]=min(t[nxt], ans[now]+s[now]);
	}

	for (LL i=1; i<=n; i++) {
		cout<<ans[i]<<"\n";
	}

	return 0;
}

D - Sum of Maximum Weights

链接

https://atcoder.jp/contests/abc214/tasks/abc214_d

题解

读完题目,就知道这是一个最短路径问题。最短路径可以使用并查集来完成。
本题基本上属于最短路径问题模板题。

AC 代码

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLL;

const LL INF=4e18;
//并查集 
const int MAXN=1e5+10;
struct EDGE {
	LL u,v,w;
} e[MAXN];
LL fa[MAXN];//父亲
LL sa[MAXN]; 
void init(LL n) {
	for (LL i=0; i<=n; i++) {
		fa[i]=i;
		sa[i]=1;
	}
}
LL find(LL x) {
	if (fa[x]!=x) {
		fa[x]=find(fa[x]);
	}
	return fa[x];
}
void join(LL x, LL y) {
	x=find(x);
	y=find(y);
	sa[y]+=sa[x];
	fa[x]=y;
}

bool mycmp(const EDGE &x, const EDGE &y) {
	return x.w<y.w;
}

int main() {
#if 1
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#endif
	//freopen("00.in", "r", stdin);
	//freopen("00.out", "w", stdout);
	LL n;
	cin>>n;
	init(n);//初始化并查集 
	for (LL i=1; i<n; i++) {
		cin>>e[i].u>>e[i].v>>e[i].w;
	}
	sort(e+1, e+n, mycmp);
	
	LL ans=0;
	for (LL i=1; i<n; i++) {
		ans+=sa[find(e[i].u)]*sa[find(e[i].v)]*e[i].w;
		join(e[i].u, e[i].v);
	}
	cout<<ans<<"\n";
	
	return 0;
}

E - Packing Under Range Regulations

链接

https://atcoder.jp/contests/abc214/tasks/abc214_e

题解

数据结构体,使用优先队列搞定。

AC代码

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLL;

const LL INF=4e18;
const int MAXN=2e5+10;
struct NODE {
	LL x, y;
	bool operator<(const struct NODE &xx) const {
		return x<xx.x;
	}
} a[MAXN];

int main() {
#if 1
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#endif
	//freopen("00.in", "r", stdin);
	//freopen("00.out", "w", stdout);
	LL T;
	cin>>T;
	while (T--) {
		LL n;
		cin>>n;
		LL maxx=0;
		for (LL i=1; i<=n; i++) {
			cin>>a[i].x>>a[i].y;
			maxx=max(maxx, a[i].y);
		}
		sort(a+1, a+n+1);
		
		priority_queue<LL, vector<LL>, greater<LL> > Q;
		bool flag=true;
		for (LL i=1; i<=n && flag; i++) {
			for (LL j=a[i-1].x; j<a[i].x && Q.size(); j++) {
				LL fr = Q.top(); 
				Q.pop();
				if (fr < j) {
					flag = false; 
					break;
				}
			}
			Q.push(a[i].y);
		}
		for (LL i=a[n].x; i<=maxx+1 && Q.size(); i++) {
			LL fr = Q.top(); 
			Q.pop();
			if (fr < i) {
				flag = false; 
				break;
			}
		}
		
		if (flag) {
			cout<<"Yes\n";
		} else {
			cout<<"No\n";
		}
	}
	
	return 0;
}
<think>好的,用户现在想找AtCoderBeginner Contest408的题解或解题思路。我需要先确认这个比赛是否已经结束,以及是否有公开的题解资源。由于AtCoder通常会在比赛后一段时间内发布官方题解,但有时候社区成员或博客作者也会分享他们的解题方法。首先,我应该检查用户提供的引用内容,但看起来用户之前的引用是关于其他比赛的,比如ABC093和ABC405,可能与当前问题无关。不过,用户可能需要类似的解题思路结构,比如分题讲解、代码示例等。接下来,我需要考虑用户可能的真实需求。他们可能参加了比赛但遇到困难,或者想通过题解来学习算法和编程技巧。因此,回答需要结构清晰,分题目讲解思路,并给出关键点的解决方法,可能的话提供代码示例。 由于我无法直接访问外部网站,无法提供最新的ABC408的具体题解,但可以给出一般性的解题步骤和常见问题的解决方法。例如,对于ABC的题目,通常前几题涉及基础算法、模拟、数学问题等,后面题目可能涉及动态规划、图论等更复杂的算法。需要注意的是,用户可能希望得到具体的解题思路,比如每道题的关键点、算法选择以及代码实现。因此,我应该分题目进行说明,可能按照A到F题的顺序,逐一简要讲解。另外,用户可能需要参考之前的类似题解的格式,比如分题说明、代码示例等。同时,根据用户之前的引用中提到的代码结构,可能需要使用Python或C++等语言的代码示例。最后,生成的相关问题应该围绕如何准备AtCoder比赛、常见题型解析、算法学习资源等,帮助用户进一步深入学习。</think>### AtCoder Beginner Contest 408 题解思路概述 根据AtCoder比赛惯例,ABC 408包含6道题目(A-F),难度递增。以下为通用解题框架: #### A题(基础语法题) 通常考察输入输出和简单计算。例如: ```python a, b = map(int, input().split()) print(a + b % 24) ``` **关键点**:注意时间循环处理[^1] #### B题(条件判断) 可能涉及字符串处理或坐标判断。例如检测网格中的特定模式: ```python grid = [input() for _ in range(9)] count = 0 for i in range(9): for j in range(9): if grid[i][j] == '#' and check_pattern(i,j): count +=1 print(count) ``` #### C题(贪心/数学) 常需数学建模,如求最大最小值的排列组合: $$ \max\left(\sum_{i=1}^n a_i \cdot b_{\sigma(i)}\right) $$ 可通过排序后对应相乘解决[^2] #### D题(图论/动态规划) 典型解法示例: ```python from collections import deque def bfs(start): q = deque([start]) dist = [-1]*(n+1) dist[start] = 0 while q: u = q.popleft() for v in graph[u]: if dist[v] == -1: dist[v] = dist[u]+1 q.append(v) return max(dist) ``` #### E-F题(高级算法) 可能涉及: 1. 线段树区间查询 2. 网络流建模 3. 组合数学优化
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力的老周

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值