AtCoder Beginner Contest 326

1|0A - 2UP3DOWN


#include<bits/stdc++.h> using namespace std; #define int long long void solve() { int a, b; cin >> a >> b; if (a < b and b - a <= 2) cout << "Yes\n"; else if (a > b and a - b <= 3) cout << "Yes\n"; else cout << "No\n"; return; } int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); solve(); return 0; }

2|0B - 326-like Numbers


#include<bits/stdc++.h> using namespace std; #define int long long void solve() { } int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); int n; cin >> n; for( int a , b , c; n ; n ++ ){ a = n % 10 , b = ( n / 10 ) % 10 , c = n / 100; if( b * c == a ){ cout << n << "\n"; return 0; } } return 0; }

3|0C - Peak


#include<bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); int n, m; cin >> n >> m; vector<int> a(n); for (auto &i: a) cin >> i; sort(a.begin(), a.end()); int res = 0; for( int l = 0 , r = 0 ; l < n ; l ++ ){ while( r+1 < n and a[r+1] - a[l] < m ) r ++; res = max( res , r - l + 1); } cout << res << "\n"; return 0; }

4|0D - ABC Puzzle


因为n 的范围很小,所以可以直接暴搜过去,加一些剪枝就能跑的飞快

#include <bits/stdc++.h> using namespace std; #define int long long using i32 = int32_t; using vi = vector<int>; using pii = pair<int, int>; const int inf = 1e10, INF = 1e18; const int mod = 998244353; const int N = 1e6; i32 main() { ios::sync_with_stdio(false), cin.tie(nullptr); int n; string r, c; cin >> n >> r >> c; vector g(n, vector<char>(n, '.')); vi visR(n), visC(n); auto dfs = [&](auto &&self, int x, int y) -> void { if (y == n) { if (visR[x] < 7) return; self(self, x + 1, 0); return; } if (x == n) { bool flag = true; for (int i = 0; flag and i < n; i++) if (visR[i] != 7 or visC[i] != 7) flag = false; for (int i = 0; flag and i < n; i++) { for (int j = 0; flag and j < n; j++) { if (g[i][j] == '.') continue; if (g[i][j] != r[i]) flag = false; break; } for (int j = 0; flag and j < n; j++) { if (g[j][i] == '.') continue; if (g[j][i] != c[i]) flag = false; break; } } if (flag) { cout << "Yes\n"; for (auto it: g) { for (auto c: it) cout << c; cout << "\n"; } exit(0); } return; } self(self, x, y + 1); for (int i = 0; i < 3; i++) { if ((visR[x] & (1 << i)) or (visC[y] & (1 << i))) continue; visR[x] ^= (1 << i), visC[y] ^= (1 << i); g[x][y] = char(i + 'A'); self(self, x, y + 1); visR[x] ^= (1 << i), visC[y] ^= (1 << i); g[x][y] = '.'; } }; dfs(dfs, 0, 0); cout << "No\n"; return 0; }

5|0E - Revenge of "The Salary of AtCoder Inc."


当前状态是xf[x]表示当前掷出值x为,并继到游戏结束期望获得的钱数。

显然f[n]=0

对于当前状态x,有两种情况

  1. xn掷出yx,游戏结束,后继收入为0
  2. 对于i>x,有$\frac 1 n ia_if[i]$

所以f[x]=xn×0+i=x+1n1n(f[i]+a[i])

所以倒序枚举状态,在后缀和统计一下可以O(1)的转移。

#include<bits/stdc++.h> using namespace std; #define int long long using i32 = int32_t; using vi = vector<int>; const int inf = 1e18; const int mod = 998244353; int power(int x, int y) { int res = 1; while (y) { if (y & 1) res = res * x % mod; x = x * x % mod, y /= 2; } return res; } int inv(int x) { return power(x, mod - 2); } i32 main() { ios::sync_with_stdio(0), cin.tie(0); int n; cin >> n; vi a(n); for (auto &i: a) cin >> i; vi f(n + 1); int res = 0, invN = inv(n); for (int i = n - 1; i >= 0; i--) res = (res + res * invN % mod + a[i]) % mod; cout << res * invN % mod << "\n"; return 0; }

__EOF__

本文作者PHarr
本文链接https://www.cnblogs.com/PHarr/p/17857752.html
关于博主:前OIer,SMUer
版权声明CC BY-NC 4.0
声援博主:如果这篇文章对您有帮助,不妨给我点个赞
posted @   PHarr  阅读(26)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-11-26 数据结构实验(五)二叉树
点击右上角即可分享
微信分享提示