AtCoder Beginner Contest 363
1.Codeforces Round 958 (Div. 2)2.Codeforces Round 957 (Div. 3)3.Codeforces Round 959 sponsored by NEAR (Div. 1 + Div. 2)4.Codeforces Round 960 (Div. 2)
5.AtCoder Beginner Contest 363
6.Codeforces Round 961 (Div. 2)7.AtCoder Beginner Contest 3628.Codeforces Round 962 (Div. 3)9.Pinely Round 4 (Div. 1 + Div. 2)10.Educational Codeforces Round 168 (Rated for Div. 2)11.AtCoder Beginner Contest 36712.Codeforces Round 967 (Div. 2)13.Codeforces Round 968 (Div. 2)14.Educational Codeforces Round 173 (Rated for Div. 2)15.Educational Codeforces Round 172 (Rated for Div. 2)(C-D)16.Codeforces Round 998 (Div. 3)17.2025牛客寒假算法基础集训营218.2025牛客寒假算法基础集训营1题目链接:AtCoder Beginner Contest 363
总结:前三题过于easy了,C的暴力写挂了一发。D差一点?,差一点总结;
A. Piling Up
fag:签到
B. Japanese Cursed Doll
fag: 签到
Solution:排序后求第
C. Japanese Cursed Doll
fag:模拟
Solution:暴力模拟即可
void solve(){ cin >> n >> k; string s; cin >> s; int ans = 0; sort(s.begin(), s.end()); do { bool fllag = true; for (int i = 0; i + k - 1 < n; i ++){ bool flag = true; for (int tt = i, t = i + k - 1; tt <= t; tt ++ , t --){ // 判断每一个回文 if (s[tt] != s[t]){ // 不是回文 flag = false; break; } } if (flag){ fllag = false; break; } } if (fllag) ans ++; }while (next_permutation(s.begin(), s.end())); cout << ans; }
D.Palindromic Number
fag:思维?打表?
Description:求第
Solution:考虑构造一个长度为
- 显然我们不能直接求出第
个回文数,但是能够求出第 个回文数的长度,知道长度之后就能求这个长度对应的第几个回文数。 - 打表或者模拟发现:奇数位的个数是上一位 * 10, 偶数位的个数等于上一位;如
中间可以填 个数,但是 只能将中间的数复制一下
1: 10 2: 9 3: 90 4: 90 5: 900
- 然后我们一位一位找第
个回文数的长度,得到长度之后构造就行。
Competing:构造的时候细节出错了。
void solve(){ int x; cin >> x; if (x <= 10){ cout << x - 1 << endl; return; } /* 枚举答案的位数: 2: 9 3: 90 4: 90 5: 900 */ int res = 9; LL ans = 10; // 之前的和 for (int i = 2; ; i ++){ if (i & 1){ // 奇数乘10 res = res * 10; } if (x - ans <= res){ // 避免ans + res 爆longlong x -= ans; // 当前位数的第几个数 if (i & 1){ i /= 2; int t = (x + 9) / 10; // 前缀是多少 int tt = ((x - 1) % 10 + 10) % 10; // 奇数位是几 // debug(x, t, tt); t = qmi(10, i - 1) + t - 1; string s = to_string(t); cout << s; cout << tt; reverse(s.begin(), s.end()); cout << s; cout << endl; return; } else{ // 偶数从100 ~ 999 i /= 2; int t = qmi(10, i - 1) + x - 1; string s = to_string(t); cout << s; reverse(s.begin(), s.end()); cout << s; cout << endl; return; } } ans += res; } }
E. Sinking Land
fag:优先队列 + bfs
Description:有一个
Solution:显然我们是需要bfs的,然后我们使用优先队列存储。队头的元素小于海水高度时就直接出队。
Competing:写bfs出队时,猜设置访问状态st,应该先设置状态st,再入队,否则会有许多重复的点入队
void solve(){ cin >> n >> m >> k; vector a(n + 5, vector<int>(m + 5)); vector st(n + 5, vector<int>(m + 5)); for (int i = 1; i <= n; i ++) for (int j = 1; j <= m; j ++) cin >> a[i][j]; priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> qu; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++){ if (i == 1 || i == n || j == 1 || j == m) { qu.push({a[i][j], {i, j}}); st[i][j] = true; } } int res = n * m; for (int i = 1; i <= k; i ++){ while (qu.size() && qu.top().fi <= i){ auto [t, tt] = qu.top(); qu.pop(); auto [x, y] = tt; res --; for (int j = 0; j < 4; j ++){ int dx = x + dir[j][0], dy = y + dir[j][1]; if (dx < 1 || dx > n || dy < 1 || dy > m || st[dx][dy]) continue; st[dx][dy] = true; qu.push({a[dx][dy], {dx, dy}}); } } cout << res << endl; } }
F. Palindromic Expression
fag:递归 +构造
Description:用
Solution:先考虑给定的值就是一个回文串并且里面不含
-
首先枚举
的因数,如果n mod x == 0
并且 中不含 且 是回文数; 是 的回文数,且n / x mod y == 0
,那么我们只需要考虑 ,如果构造就行。 -
因此我们定义一个函数
:如果 是回文串并且里面不含 那么直接返回。 -
否则枚举它的因数,当因数
满足上面说所的条件,递归到 。
Competing:忘记考虑因数中也不能含
int reverse(int x){ // 返回x的回文数 string t = to_string(x); reverse(t.begin(), t.end()); int y = stol(t); return y; } bool is_Hui(int x){ // 判断x是否是回文数 string s = to_string(x); for (int i = 0, j = s.size() - 1; i <= j; i ++, j --){ if (s[i] != s[j] || s[i] == '0') return false; } return true; } string f(int x){ string s = to_string(x); if (is_Hui(x)) // 如果x是回文数,并且不含0之间返回 return s; for (int i = sqrt(x) + 1; i >= 2; i --){ // 枚举x的质因数 if (x % i == 0 && to_string(i).find('0') == -1){ int y = reverse(i); // i的回文数 if ((x / i) % y == 0){ string t = f(x / i / y); if (t != "0"){ return to_string(i) + "*" + t + "*" + to_string(y); } } } } return "0"; } void solve(){ int n; cin >> n; string ans = f(n); if (ans == "0" || ans.size() > 1000) cout << -1 << endl; else cout << ans << endl; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!