AtCoder ABC378 A-D题解

比赛链接:ABC378

比较简单的一次 ABC。

Problem A:

Code

#include <bits/stdc++.h>
using namespace std;
int main(){
  	cin>>A[1]>>A[2]>>A[3]>>A[4];
  	sort(A+1,A+5);
  	if(A[1]==A[2] && A[3]==A[4])
    	cout<<2<<endl;
  	else{
    	if(A[1]==A[2] || A[2]==A[3] || A[3]==A[4])
      		cout<<1<<endl;
    	else
      		cout<<0<<endl;
  	}
  	return 0;
}

Problem B:

Code

#include <bits/stdc++.h>
using namespace std;
int q[105],r[105];
int main(){
	int N;
	cin>>N;
	for(int i=1;i<=N;i++)
		cin>>q[i]>>r[i];
	int Q;
	cin>>Q;
	while(Q--){
		int t,d;
		cin>>t>>d;
		int ans=r[t]-d%q[t]+d;
		if(r[t]-d%q[t]<0)
			ans+=q[t];
		cout<<ans<<endl;
	}
	return 0;

Problem C:

Sol

直接拿一个 map 记录每个A_iB_i即可。

Code

#include <bits/stdc++.h>
using namespace std;
map<int,int> B;
int main(){
	int N;
	cin>>N;
	for(int i=1;i<=N;i++){
		int A;
		cin>>A;
		if(B[A])
			cout<<B[A]<<endl;
		else
			cout<<-1<<endl;
		B[A]=i;
	}
	return 0;
}

Problem D:

Sol

直接 dfs 即可。

Code

#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
bool vis[20][20];
char S[20][20];
int H,W,K,ans;
void dfs(int x,int y,int step){
	if(step==K){
		ans++;
		return;
	}
	vis[x][y]=true;
	for(int i=0;i<4;i++){
		int nx=x+dx[i],ny=y+dy[i];
		if(0<=nx && nx<H && 0<=ny && ny<W && S[nx][ny]=='.' && !vis[nx][ny])
			dfs(nx,ny,step+1);
	}
	vis[x][y]=false;
}
int main(){
	cin>>H>>W>>K;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++)
			cin>>S[i][j];
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(S[i][j]=='.'){
				dfs(i,j,0);
				cout<<i<<' '<<j<<' '<<ans<<endl;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

友情提醒:不要无脑Ctrl C+Ctrl V

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值