比赛链接: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
}