AtCoder ABC351 A-D题解

比赛链接:ABC351

Problem A:

签到题。

#include <bits/stdc++.h>
using namespace std;
int main(){
	int ans=0;
	for(int i=1;i<=9;i++){
		int A;
		cin>>A;
		ans+=A;
	}
	for(int i=1;i<=8;i++){
		int B;
		cin>>B;
		ans-=B;
	}
	cout<<ans<<endl;
	return 0;
}

Problem B:

依旧水题。

#include <bits/stdc++.h>
using namespace std;
char A[105][105],B[105][105];
int main(){
	int N;
	cin>>N;
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++)
			cin>>A[i][j];
	}
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++)
			cin>>B[i][j];
	}
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			if(A[i][j]!=B[i][j]){
				cout<<i<<' '<<j<<endl;
			}
		}
	}
}

Problem C:

拿vector暴力按题意模拟即可。

#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int> seq;
    for(int i=0;i<N;i++){
        int A;
        cin>>A;
        seq.push_back(A);
        while(seq.size()>=2 && seq.back()==seq[(int)seq.size()-2]){
            seq.pop_back();
            seq.back()++;
        }
    }
    return 0;
}

Problem D:

bfs即可。

#include <bits/stdc++.h>
using namespace std;
string S[1005];
const int dx[]={0,0,-1,1};
const int dy[]={-1,1,0,0};
int H,W;
bool valid(int x,int y){
	if(0<=x && x<H && 0<=y && y<W)
		return true;
	return false;
}
int main(){
    cin>>H>>W;
    for(int i=0;i<H;i++)
        cin>>S[i];
    vector<vector<int>> bad(H,vector<int>(W,0));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j]=='#'){
                for(int k=0;k<4;k++){
                    int x=i+dx[k];
                    int y=j+dy[k];
                    if(valid(x,y))
                        bad[x][y]=1;
                }
            }
        }
    }
	vector<vector<int>> vis(H,vector<int>(W,-1));
    int ans=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(vis[i][j]==-1 && S[i][j]=='.'){
                int res=0;
                queue<pair<int,int>> que;
                vis[i][j]=i*W+j;
                que.push(make_pair(i,j));
                while(!que.empty()){
                    auto [x,y]=que.front();
                    que.pop();
                    res++;
                    if(bad[x][y])
                        continue;
                    for(int k=0;k<4;k++){
                        int nx=x+dx[k];
                        int ny=y+dy[k];
                        if(valid(nx,ny) && vis[nx][ny]!=(i*W+j)){
                            vis[nx][ny]=i*W+j;
                            que.push(make_pair(nx,ny));
                        }
                    }
                }
                ans=max(ans,res);
            }
        }
    }
    cout<<ans<<endl;
    return 0
}

相关推荐

  1. ABC341A-D题解

    2024-05-03 05:04:02       31 阅读
  2. AtCoder ABC351 A-D题解

    2024-05-03 05:04:02       11 阅读
  3. AtCoder Beginner Contest 351 A-F题解

    2024-05-03 05:04:02       13 阅读
  4. AtCoder Beginner Contest 333 A-D题解

    2024-05-03 05:04:02       29 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-05-03 05:04:02       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-03 05:04:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-03 05:04:02       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-03 05:04:02       20 阅读

热门阅读

  1. 【无标题】

    2024-05-03 05:04:02       11 阅读
  2. Docker网络详解

    2024-05-03 05:04:02       9 阅读
  3. 由特征值和特征向量求矩阵的逆

    2024-05-03 05:04:02       9 阅读
  4. VUE2从入门到精通(二)

    2024-05-03 05:04:02       12 阅读
  5. DDS 相关中文版标准资料

    2024-05-03 05:04:02       10 阅读
  6. 套接字概念的理解

    2024-05-03 05:04:02       8 阅读
  7. c++ 判断点和折线 距离

    2024-05-03 05:04:02       10 阅读
  8. Redis 实现分布式Session 登录相关细节

    2024-05-03 05:04:02       9 阅读
  9. VSCode 配置 Qt 开发环境

    2024-05-03 05:04:02       12 阅读