AtCoder Beginner Contest 278 A~E题详细讲解

本次解析涵盖AtCoder比赛中的五个题目,包括数组操作、时间判断、社交网络互动、数组更新查询及矩阵元素计数等问题,提供了详细的解题思路与代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这次比赛非常水,也许是因为上一场比赛出得太难了,有兴趣的可以点击这里

赛时:A,B,C,D,E,取得历史新高。

话不多说,本题解现在开始。

目录

A - Shift

B - Misjudge the Time

C - FF 

D - All Assign Point Add 

E - Grid Filling


A - Shift

A - ShiftAtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.https://atcoder.jp/contests/abc278/tasks/abc278_a

 以上是对shift的英文翻译,和上次比赛一样,不知道是几个意思。

题目大意:有一个长度为n的数组,进行k次操作:每次删掉第一位,并在最后放进一个0。输出操作后的数组。

题目思路:用队列(queue)模拟。

#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	int n,k; cin>>n>>k;
	queue<int>q;
	for(int i=0;i<n;i++){
		int x; cin>>x;
		q.push(x);
	}
	for(int i=0;i<k;i++){
		q.pop();
		q.push(0);
	}
	while(!q.empty()){
	    cout<<q.front()<<" ";
	    q.pop();
	}
    return 0;
}
//ACplease!!!

B - Misjudge the Time

谁家的钟这么奇怪?就不能搞个横向显示的?

B - Misjudge the TimeAtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.https://atcoder.jp/contests/abc278/tasks/abc278_b

题目大意:高桥买了一个台钟。时钟显示24小时系统中AB:CD处的时间,如图1所示。例如,图2中的时钟显示7:58。高桥决定,如果某个时间满足以下条件,则将其称为混淆时间:

◇ 在交换时钟的右上和左下数字后,它仍然读取24小时系统中的有效时间。

例如,图3中的时钟显示20:13。在交换其右上角和左下角的数字后,显示为21:03。因此,20:13是一个令人困惑的时间。时钟现在显示H:M。在24小时系统中查找下一个令人困惑的时间(包括现在)。

题目思路: 暴力枚举。

#include<bits/stdc++.h>
using namespace std;
bool time(int h,int m){
	if(h<0||h>23) return 0;
	if(m<0||m>59) return 0;
	return 1;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	int h,m; cin>>h>>m;
	while(true){
		if(m==60) h++,m=0;
		if(h==24) h=0;
		int a=h/10,b=h%10,c=m/10,d=m%10;
		swap(b,c);
		int th=a*10+b;
		int tm=c*10+d;
		if(time(th,tm)){
			cout<<h<<" "<<m;
			return 0;
		}
		m++;
	}
    return 0;
}
//ACplease!!! 

C - FF 

C - FFAtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.https://atcoder.jp/contests/abc278/tasks/abc278_cFF是什么鬼?

题目大意:在某网站中有n个用户。要进行q次操作,每次要输入t,a,b。

若t=1,让a关注b;若t=2,让a取关b;若t=3,问a和b是否互关。

题目思路:模拟,map套map。

#include<bits/stdc++.h>
using namespace std;
map<int,map<int,bool> >f;
void yesno(bool x,bool y){
	if(x&&y) puts("Yes");
	else puts("No");
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	int n,q; cin>>n>>q;
	while(q--){
		int t,a,b; cin>>t>>a>>b;
		if(t==1) f[a][b]=1;
		if(t==2) f[a][b]=0;
		if(t==3) yesno(f[a][b],f[b][a]);
	}
    return 0;
}
//ACplease!!!

D - All Assign Point Add 

D - All Assign Point AddAtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.https://atcoder.jp/contests/abc278/tasks/abc278_d题目名称的翻译:所有指定点添加。

题目大意:有一个长度为n的数组,需要做q次操作。有以下三种操作:

  • 1 x :把数组中的每一位变成x。
  • 2 i x:把第i位加上x。
  • 3 i:输出第i位上面是多少。

题目思路:对于每种操作时,按以下方式操作。可以把第1种操作中的O(n)复杂度变成O(1)。

需要一个map和一个变量every。

  • 1 x :清空map,every=x。
  • 2 i x:将map的第i位加上x,若这一位是空的,先赋上every再操作。
  • 3 i:输出map第i位上面是多少,若为空,输出every。
#include<bits/stdc++.h>
using namespace std;
map<int,long long>a;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	long long n,every=0; cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	long long q; cin>>q;
	while(q--){
		long long t; cin>>t;
		if(t==1){
			int x; cin>>x;
			every=x;
			a.clear();
		}if(t==2){
			int j,x; cin>>j>>x;
			if(a[j]==0) a[j]=every;
			a[j]+=x;
		}if(t==3){
			int j; cin>>j;
			if(a[j]==0) cout<<every<<endl;
			else cout<<a[j]<<endl;
		}
	}
    return 0;
}
//ACplease!!! 

E - Grid Filling

E - Grid FillingAtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.https://atcoder.jp/contests/abc278/tasks/abc278_e俗话说:“暴力出奇迹”。这道题有效地证明了这一点。

题目大意:你有一个整数矩阵,从上到下有H行,从左到右有W列。我们用(i,j)表示顶部第i行和左侧第j列的正方形。(i,j) 上写有1到N之间的整数 Aij 。给定整数h和w。对于所有对(k,l), 解决以下问题:如果你涂黑正方形(i,j),使得k<i≤k+h和l<j≤l+w,有多少个不同的整数写在没有涂黑的正方形上?然而,请注意,您实际上并没有将正方形涂黑(也就是说,问题是独立的)。

题目思路:数据很水,四重循环能过。

#include<bits/stdc++.h>
using namespace std;
int a[310][310];
vector<int>cnt(310);
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	int h,w,n,r,c; cin>>h>>w>>n>>r>>c;
	for(int i=0;i<308;i++) cnt[i]=0;
	for(int i=1;i<=h;i++) for(int j=1;j<=w;j++){
		cin>>a[i][j];
		cnt[a[i][j]]++;
	}
	for(int i=1;i<=h-r+1;i++){
		for(int j=1;j<=w-c+1;j++){
			vector<int>tcnt(cnt);
			for(int k=i;k<=i+r-1;k++){
				for(int l=j;l<=j+c-1;l++){
					tcnt[a[k][l]]--;
				}
			}
			int ans=0;
			for(int k=1;k<=n;k++) if(tcnt[k]) ans++;
			cout<<ans<<" ";
		}
		cout<<endl;
	}
    return 0;
}
//ACplease!!!

谢谢大家的阅读,下次比赛再见!ヾ( ̄▽ ̄)Bye~Bye~

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值