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> ...
随机推荐
- python中pip下载慢或报错的解决方法
一:问题 python的pip在安装包时,有时会报错超时,排除包名写错的原因,一般这种问题是因为网络下载过慢,导致超时 二:解决方案 我们可以设置pip镜像源下载,能够提升pip下载速度,解决报错问题 ...
- 【外包杯】【报错】微信小程序 “[app.json 文件内容错误]app.json:未找到[“pages”][0]对应 pages/xx/xx.wxml(或其他)文件” 报错 的简单解决方案(已解决)
问题的解决方案 删除components目录下的uni-link文件夹
- 【Javaweb】瑞吉外卖你冲不冲?冲冲!冲!冲冲!(数据库环境搭建)(maven项目搭建)一
图形界面创建数据库(Navicat) 命令行方式创建 瑞吉项目一共涉及到十一张表 导入表结构,既可以使用上面的图形界面,也可以使用MySQL命令: 通过命令导入表结构时,注意sql文件不要放在中文目录 ...
- AutoCAD ObjectARX 二次开发(2020版)--2,手动创建CAD二次开发项目--
本项目使用手动创建,意为不使用SDK模板. 从Visual Studio的"文件"下拉菜单中,选择"新建"->"项目...". 在出现 ...
- vim的各种快捷键
目录 一.准备一份用于练习的文件 二.命令模式下的快捷键 1.移动光标 2.删除文字 3.复制粘贴 4.撤销上一次操作 5.恢复上一次撤销的操作 6.查找 7.替换单个字符 8.光标移动到最左边 9. ...
- 浅析MySQL代价模型:告别盲目使用EXPLAIN,提前预知索引优化策略
背景 在 MySQL 中,当我们为表创建了一个或多个索引后,通常需要在索引定义完成后,根据具体的数据情况执行 EXPLAIN 命令,才能观察到数据库实际使用哪个索引.是否使用索引.这使得我们在添加新索 ...
- transformer模型
Transformer由谷歌团队在论文<Attention is All You Need>提出,是基于attention机制的模型,最大的特点就是全部的主体结构均为attention. ...
- 华企盾DSC防泄密软件:svn、git更新后有感叹号常见处理方法
1.查看客户端日志检查TSVNcache.exe进程是否是legal:1 2.TSVNcache.exe进程是否允许访问未配置加密进程的后缀 3.svn服务器不是加密进程也未装网络驱动,或者加密类型未 ...
- Date、正则表达式练习
Date.正则表达式练习 package com.guoba.date; import java.text.SimpleDateFormat; import java.util.Calendar; i ...
- vue 2实战系列 —— 复习Vue
复习Vue 近期需要接手 vue 2的项目,许久未写,语法有些陌生.本篇将较全面复习 vue 2. Tip: 项目是基于 ant-design-vue-pro ant-design-vue-pro 由 ...