It has been 890 days since the last update, the content of the article may be outdated.
Atcoder Beginner Contest 244
By xiaruize 20220320
A - Last Letter
Method & Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include<bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long #define ALL(a) (a).begin(), (a).end() #define pb push_back #define mk make_pair #define pii pair<int,int> #define pis pair<int,string> #define sec second #define ll long long #define fir first #define sz(a) int((a).size()) #define rep(i,x,y) for(int i=x;i<=y;i++) #define repp(i,x,y) for(int i=x;i>=y;i--) #define Yes cout<<"Yes"<<endl #define YES cout<<"YES"<<endl #define No cout<<"No"<<endl; #define NO cout<<"NO"<<endl; #define multitest(t) while(t--) solve(); #define double long double const int INF=0x3f3f3f3f; const int Mod=1000000007; const int N=1e5+10;
inline int rd() {int x = 0, w = 1;char ch = 0;while (ch < '0' || ch > '9'){if (ch == '-') w = -1;ch = getchar();}while (ch >= '0' && ch <= '9'){x = x * 10 + (ch - '0');ch = getchar();}return x * w;} inline void wt(int x) {static int sta[35];int top = 0;do {sta[top++] = x % 10, x /= 10;} while (x);while (top) putchar(sta[--top] + 48);}
signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; string s; cin>>n>>s; cout<<s[n-1]<<endl; return 0; }
|
B - Go Straight and Turn Right
Method
模拟
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long #define ALL(a) (a).begin(), (a).end() #define pb push_back #define mk make_pair #define pii pair<int, int> #define pis pair<int, string> #define sec second #define ll long long #define fir first #define sz(a) int((a).size()) #define rep(i, x, y) for (int i = x; i <= y; i++) #define repp(i, x, y) for (int i = x; i >= y; i--) #define Yes cout << "Yes" << endl #define YES cout << "YES" << endl #define No cout << "No" << endl; #define NO cout << "NO" << endl; #define multitest(t) \ while (t--) \ solve(); #define double long double const int INF = 0x3f3f3f3f; const int Mod = 1000000007; const int N = 1e5 + 10;
const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, -1, 0, 1}; int n; string s; int now = 0;
signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> s; int x, y; x = y = 0; for (int i = 0; i < n; i++) { if (s[i] == 'R') { now = (now + 1) % 4; } else { x += dx[now]; y += dy[now]; } } cout << x << ' ' << y << endl; return 0; }
|
C - Yamanote Line Game
Before Method
此生仅能见到Atcoder出交互题!!!
Method
似乎还是暴力模拟。。。
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long #define ALL(a) (a).begin(), (a).end() #define pb push_back #define mk make_pair #define pii pair<int, int> #define pis pair<int, string> #define sec second #define ll long long #define fir first #define sz(a) int((a).size()) #define rep(i, x, y) for (int i = x; i <= y; i++) #define repp(i, x, y) for (int i = x; i >= y; i--) #define Yes cout << "Yes" << endl #define YES cout << "YES" << endl #define No cout << "No" << endl; #define NO cout << "NO" << endl; #define multitest(t) \ while (t--) \ solve(); #define double long double const int INF = 0x3f3f3f3f; const int Mod = 1000000007; const int N = 1e5 + 10;
int n; bool vis[2005];
signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int j = 1; j <= n; j++) { for (int i = 1; i <= 2 * n + 1; i++) { if (!vis[i]) { cout << i << endl; vis[i] = true; break; } } int x; cin >> x; vis[x] = true; }
for (int i = 1; i <= 2 * n + 1; i++) { if (!vis[i]) { cout << i << endl; vis[i] = true; break; } } return 0; }
|
D - Swap Hats
Method
手动模拟一下,当原始为123时,只有123,312,231可行
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#include <bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long #define ALL(a) (a).begin(), (a).end() #define pb push_back #define mk make_pair #define pii pair<int, int> #define pis pair<int, string> #define sec second #define ll long long #define fir first #define sz(a) int((a).size()) #define rep(i, x, y) for (int i = x; i <= y; i++) #define repp(i, x, y) for (int i = x; i >= y; i--) #define Yes cout << "Yes" << endl #define YES cout << "YES" << endl #define No cout << "No" << endl #define NO cout << "NO" << endl #define multitest(t) \ while (t--) \ solve(); #define double long double const int INF = 0x3f3f3f3f; const int Mod = 1000000007; const int N = 1e5 + 10;
char a[4]; char b[4]; int res[4]; int ans[3][3] = {{1, 2, 3}, {3, 1, 2}, {2, 3, 1}};
signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); for (int i = 1; i <= 3; i++) cin >> a[i]; for (int i = 1; i <= 3; i++) cin >> b[i]; for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { if (b[i] == a[j]) { res[i] = j; } } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (res[j + 1] != ans[i][j]) break; if (j == 2) { Yes; return 0; } } } No; return 0; }
|
E - King Bombee
Method
dp题 dpi,j,0/1表示当前考虑第i条边,到点j,x被经过了奇数/偶数次
dp0,j,0={0 (j=s)1 (j=s)dp0,j,1=0dpi+1,j,x=k∈adj(j)∑dpi,k,x(j=x)dpi+1,X,x=k∈adj(X)∑dpi,k,1−x 答案:dpK,T,0
时间复杂度: O((N+M)K)
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include <bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long #define ALL(a) (a).begin(), (a).end() #define pb push_back #define mk make_pair #define pii pair<int, int> #define pis pair<int, string> #define sec second #define ll long long #define fir first #define sz(a) int((a).size()) #define rep(i, x, y) for (int i = x; i <= y; i++) #define repp(i, x, y) for (int i = x; i >= y; i--) #define Yes cout << "Yes" << endl #define YES cout << "YES" << endl #define No cout << "No" << endl; #define NO cout << "NO" << endl; #define multitest(t) \ while (t--) \ solve(); #define double long double const int INF = 0x3f3f3f3f; const int Mod = 1000000007; const int MOD = 998244353; const int N = 2010;
int n, m, k, s, t, x; vector<pii> edge; int dp[2005][2005][2];
signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> k >> s >> t >> x; s--; t--; x--; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; u--; v--; edge.pb(mk(u, v)); } dp[0][s][0] = 1; for (int i = 0; i < k; i++) { for (auto [u, v] : edge) { (dp[i + 1][v][0 ^ (v == x)] += dp[i][u][0]) %= MOD; (dp[i + 1][u][0 ^ (u == x)] += dp[i][v][0]) %= MOD; (dp[i + 1][v][1 ^ (v == x)] += dp[i][u][1]) %= MOD; (dp[i + 1][u][1 ^ (u == x)] += dp[i][v][1]) %= MOD; } } cout << dp[k][t][0] << endl; return 0; }
|