AtCoder Beginner Contest 250
A - Adjacent Squares
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
ios::sync_with_stdio(false),cin.tie(nullptr);
int h,w,r,c;
cin>>h>>w>>r>>c;
int dir[][2]={1,0,0,1,-1,0,0,-1};
int cnt=0;
for(int i=0;i<4;i++){
int x=r+dir[i][0],y=c+dir[i][1];
if(x>=1&&x<=h&&y>=1&&y<=w)cnt++;
}
cout<<cnt<<endl;
return 0;
}
B - Enlarged Checker Board
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
const int maxn = 1e2 + 10;
const int N = 6e6 + 100;
int dp[maxn][maxn];
void solve() {
int n,a,b;
cin>>n>>a>>b;
for (int i = 0; i < n*a; ++i) {
for (int j = 0; j < n*b; ++j) {
cout<<(i/a+j/b & 1?'#':'.');
}
cout<<endl;
}
}
signed main() {
int _ = 1;
while (_--) {
solve();
}
return 0;
}
C - Adjacent Swaps
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
const int maxn = 1e6 + 10;
const int N = 6e6 + 100;
int a[maxn],b[maxn];
void solve() {
int n,q;
cin>>n>>q;
for (int i = 0; i <=n; ++i) {
a[i]=b[i]=i;
}
while (q--){
int x;
cin>>x;
int opt=a[x];
if(opt==n) opt=n-1;
swap(b[opt],b[opt+1]);
swap(a[b[opt]],a[b[opt+1]]);
}
for (int i = 1; i <=n; ++i) {
cout<<b[i]<<" ";
}
}
signed main() {
int _ = 1;
while (_--) {
solve();
}
return 0;
}
|