Divide by Zero 2021 and Codeforces Round #714 (Div. 2) 个人补题记录
补题链接:Here
A. Array and Peaks
题意:给定 数组大小 \(n\) 和 峰值点 \(k\) 请问是否存在这样的排序,不存在则输出-1
先序从 i = 2 开始填,依次 i += 2 ,如果这样还有不够即 \(k \ne 0\) 则肯定不存在这种排序。
接下来就是填空位了
AC 代码:
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
int nn = n;
for (int i = 2; i <= n; i += 2) {
if (k == 0) break;
a[i] = nn--, k--;
}
if (k) {
cout << -1 << "\n";
return;
}
int cur = 1;
for (int i = 1; i <= n; ++i)
if (!a[i]) a[i] = cur++;
for (int i = 1; i <= n; ++i) cout << a[i] << " ";
cout << "\n";
}
B. AND Sequences
这道题,仍是看了题解都没怎么理解是这样子做的
using ll = long long;
const ll mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int &x : a) cin >> x;
int h = 0;
for (int i = 0; i < 30; ++i) {
h |= 1 << i;
for (int x : a)
if (not((x >> i) & 1)) h &= ~(1 << i);
}
int c = count(a.begin(), a.end(), h);
ll ans = (ll)c * (c - 1) % mod;
for (int i = 1; i <= n - 2; ++i) ans = ans * i % mod;
cout << ans << '\n';
}
C. Add One
题意很容易懂:现给一个大数 \(n\) 和 \(m\) 次操作机会,每次操作都要使 \(n\) 的每个位数 + 1,满十进一。如:\(1912 \to21023\)
思路:
由于 \(m\) 的范围在 \([1,2e5]\) 就别想着暴力了,尝试 DP + 预处理
预处理部分: $DP_{(i,j)}\ $ 代表第 i 次操作时位数值时 j 的变化值
dp(i,j) = j < 9\ ?\ dp(i - 1,j + 1) : (dp(i-1,0) + dp(i - 1,1)\ \%\ mod)
\]
int M = 2e5 + 10;
vector<vector<int>> dp(M + 1, vector<int>(10));
void init() {
for (int i = 0; i < 10; ++i) dp[0][i] = 1;
for (int i = 1; i <= M; ++i)
for (int j = 0; j < 10; ++j) {
if (j < 9) dp[i][j] = dp[i - 1][j + 1];
else
dp[i][j] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
}
}
所以根据 DP 数组,可以快速得到输入值 n,m的情况下最后的位数
void solve() {
string s;
int m;
cin >> s >> m;
ll ans = 0;
for (char c : s) ans = (ans + dp[m][c - '0']) % mod;
cout << ans << "\n";
}
赛后看了下官方题解,发现可以把二维DP压缩为一位DP
\(dp_i\) 定义为对数字 \(10\) 进行 \(i\) 次运算以后的字符串长度
\(dp_i = 2,∀\ i\) in \([0,8]\)
\(dp_i = 3,\) if \(i = 9\)
即对数字 \(10\) 进行 \(9\) 次运算后最终数字为 \(109\)
对于其他情况:\(dp_i = dp_{i-9} + dp_{i - 10}\)
长度是 \(i - 9\) 次运算和 \(i - 10\) 次运算的和
这里同样先预处理
最后的答案为 \(ans = \sum_{i = 1}^{|s|}((m + (int)(s[i] - '0') < 10)?1:dp_{m-10+(int)(s[i] - '0')})\)
- 时间复杂度为:\(\mathcal{O}(m+t·|s|)\)
#define int long long
const int max_n = 200005, mod = 1000000007;
int dp[max_n];
signed main() {
for (int i = 0; i < 9; i++) dp[i] = 2;
dp[9] = 3;
for (int i = 10; i < max_n; i++) {
dp[i] = (dp[i - 9] + dp[i - 10]) % mod;
}
ios_base::sync_with_stdio(false), cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
int ans = 0;
while (n > 0) {
int x = n % 10;
ans += ((m + x < 10) ? 1 : dp[m + x — 10]);
ans %= mod;
n /= 10;
}
cout << ans << "\n";
}
return 0;
}
Divide by Zero 2021 and Codeforces Round #714 (Div. 2) 个人补题记录的更多相关文章
- Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400
题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 ...
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs
地址:http://codeforces.com/contest/768/problem/D 题目: D. Jon and Orbs time limit per test 2 seconds mem ...
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C - Jon Snow and his Favourite Number
地址:http://codeforces.com/contest/768/problem/C 题目: C. Jon Snow and his Favourite Number time limit p ...
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1
地址:http://codeforces.com/contest/768/problem/B 题目: B. Code For 1 time limit per test 2 seconds memor ...
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch
地址:http://codeforces.com/problemset/problem/768/A 题目: A. Oath of the Night's Watch time limit per te ...
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)
C题卡了好久,A掉C题之后看到自己已经排在好后面说实话有点绝望,最后又过了两题,总算稳住了. AC:ABCDE Rank:191 Rating:2156+37->2193 A.Oath of t ...
- Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined)
思路:把边看成点,然后每条边只能从下面的边转移过来,我们将边按照u为第一关键字,w为第二关键字排序,这样就能用线段树维护啦. #include<bits/stdc++.h> #define ...
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A B 水 搜索
A. Oath of the Night's Watch time limit per test 2 seconds memory limit per test 256 megabytes input ...
- 【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones
打表找规律即可. 1,1,2,2,2,3,3,3,3,4,4,4,4,4... 注意打表的时候,sg值不只与剩下的石子数有关,也和之前取走的方案有关. //#include<cstdio> ...
随机推荐
- ABAP 自定义附件
SWO1 关键字 *------------------------------------------------------------* REPORT ZTEST_CSW1. *TABLES ...
- KR4-KP4
serdes测试中经常遇到KR4 和KP4, KR4指的是FEC 528 514对应25X4的100G KP4对应FEC 544 514,56/100x4 的200/400G链路 KP4应用比较广泛, ...
- 87 GB 模型种子,GPT-4 缩小版,超越ChatGPT3.5,多平台在线体验
瞬间爆火的Mixtral 8x7B 大家好,我是老章 最近风头最盛的大模型当属Mistral AI 发布的Mixtral 8x7B了,火爆程度压过Google的Gemini. 缘起是MistralAI ...
- C++ Qt开发:StandardItemModel数据模型组件
Qt 是一个跨平台C++图形界面开发库,利用Qt可以快速开发跨平台窗体应用程序,在Qt中我们可以通过拖拽的方式将不同组件放到指定的位置,实现图形化开发极大的方便了开发效率,本章将重点介绍Standar ...
- 【笔记整理】使用Session会话保持
import requests if __name__ == '__main__': # Session对象实现了客户端和服务器端的每次会话保持功能. session = requests.Sessi ...
- 开源数据血缘和元数据管理框架DataHub的血缘摄取 V0.12.1版本
DataHUb的安装很简单:你有绿色上网就soeasy 前置条件,你已经运行好DataHub整个Docker-Compse服务 打开地址:http://host:9002/ 输入账号DataHub 密 ...
- Educational Codeforces Round 159 总结
最失败的一集. C 开题顺序搞错,不小心先开了C,以为是A.还好C不难. 题意大概是在给定的数组最后添一个数(所有数两两不同),再自定义一个数 \(k\) ,数组中每个数可以加上若干个 \(k\) , ...
- 一个WPF版的Layui前端UI库
前言 相信做.NET后端开发的很多小伙伴都用过Layui前端UI组件库,今天我们分享一个WPF版的Layui前端UI样式库:Layui-WPF. WPF介绍 WPF 是一个强大的桌面应用程序框架,用于 ...
- VSCode 中优雅地编写 Markdown
VSCode 中优雅地编写 Markdown 在 VSCode 中编写 Markdown 有几个无法拒绝的优势,首先是顺手方便,常写代码的同学打开 VSCode 各项功能和快捷键使用的都比较熟练,可以 ...
- 【OpenCV】在 Mac OS 上使用 EmguCV
前言 OpenCV是一个基于Apache2.0许可(开源)发行的跨平台计算机视觉和机器学习软件库,它具有C++,Python,Java和MATLAB接口,并支持Windows,Linux,Androi ...