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> ...
随机推荐
- MySQL锁粒度是什么意思?MySQL锁粒度是什么?
MySQL锁粒度就是我们通常所说的锁级别.数据库引擎具有多粒度锁定,允许一个事务锁定不同类型的资源. MySQL数据库有三种锁的级别,分别是:页级锁.表级锁 .行级锁. 锁粒度 锁粒度就是我们通常所说 ...
- .net下优秀的日志框架Serilog,你用上了吗?强烈推荐
在 .NET 开发中,Serilog 是一款广受欢迎的日志库,它提供了强大的日志记录功能,具有丰富的特性和高度的可扩展性.Serilog 的优秀之处包括: 可扩展性: Serilog 可以轻松扩展以满 ...
- H5自适应
一.设置html的font-size,使用rem作为单位 假设设计稿宽度750px,屏幕宽高750px, 1.1rem=屏幕宽度/设计稿宽度*100px,适合用px表示宽度 1rem=100px re ...
- java中父类方法return this.对象还是变量,子类去调用this.这个方法的问题
这个问题很简单 public class this_test01 { public static void main(String[] args) { zi j=new zi(); j.pri(); ...
- [CF1854C] Expected Destruction
题目描述 You have a set $ S $ of $ n $ distinct integers between $ 1 $ and $ m $ . Each second you do th ...
- Rong晔大佬教程学习(2):取指
1.rvseed_defines.v(定义了一些参数,没有实际意义) 该文件定义了一些基本参数,在后续的代码中都会调用该文件 // simulation clock period `define SI ...
- 华企盾DSC服务器无法启动常见处理方法
先查看<服务问题判断>文档.常见的 1.授权已经过期--需延长授权 2.ERR_BASE64 – 机器码变更 3.不能在该计算机上使用该数据库,需要解锁才可以--打开服务器配置解锁数据库 ...
- 使用dtd定义元素
- ElasticSearch之cat data frame analytics API
命令样例如下: curl -X GET "https://localhost:9200/_cat/ml/data_frame/analytics?v=true&pretty" ...
- libGDX游戏开发之菜单界面(四)
libGDX游戏开发之菜单界面(四) libGDX系列,游戏开发有unity3D巴拉巴拉的,为啥还用java开发?因为我是Java程序员emm-国内用libgdx比较少,多数情况需要去官网和googl ...