补题链接: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 的变化值

\[init:dp[0][i] = 1\\
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) 个人补题记录的更多相关文章

  1. 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 ...

  2. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined)

    思路:把边看成点,然后每条边只能从下面的边转移过来,我们将边按照u为第一关键字,w为第二关键字排序,这样就能用线段树维护啦. #include<bits/stdc++.h> #define ...

  9. 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 ...

  10. 【博弈论】【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> ...

随机推荐

  1. linux笔记一(基础命令)

      总结: 1.ls – List ls会列举出当前工作目录的内容(文件或文件夹),就跟你在GUI中打开一个文件夹去看里面的内容一样. 2.mkdir – Make Directory mkdir 用 ...

  2. Curator

  3. SpringBoot 这么实现动态数据源切换,就很丝滑!

    大家好,我是小富- 简介 项目开发中经常会遇到多数据源同时使用的场景,比如冷热数据的查询等情况,我们可以使用类似现成的工具包来解决问题,但在多数据源的使用中通常伴随着定制化的业务,所以一般的公司还是会 ...

  4. Swagger配置类

    Swagger配置类 package com.guoba.servicebase.config; import com.google.common.base.Predicates; import or ...

  5. 三个月我迁移了100PB数据

    2023年马上结束,这一年做了不少事情,有一项我可以吹好几年,忍不住和大家分享一下啊. 需求 去年底收到一项需求,要求2个月内从某云存储迁移100PB数据到微软云存储,包含几百亿个文件.当时听到这个数 ...

  6. ElasticSearch之Get index settings API

    获取指定索引的参数的值. 获取指定索引的全部参数,命令样例如下: curl -X GET "https://localhost:9200/testindex_002/_settings?pr ...

  7. 从零玩转Yaip使用-cong-ling-wan-zhuan-yaip-shi-yong

    title: 从零玩转Yaip使用 date: 2021-07-16 15:47:17.624 updated: 2021-12-26 17:43:12.255 url: https://www.yb ...

  8. 当创建一个ingress后,kubernetes会发什么?

    本文分享自华为云社区<当创建一个ingress后,kubernetes会发什么?>,作者:可以交个朋友. 一.Ingress概述 Ingress是一组路由转发规则合集,将集群内部服务通过7 ...

  9. el-table 设置合并行或列时,显示错乱问题

    1. 需求效果图: 2. 接口数据格式: 点击查看代码 const list = [ { contractNo: "CAI-20220801001", contractItem: ...

  10. 踩坑ffmpeg录制的mp4无法在浏览器上播放

    前言 使用ffmpeg编译好的程序在电脑上进行音视频转换,可以参考这篇:<windows电脑FFmpeg安装教程手把手详解_windows安装ffmpeg>,而我们要做的是在游戏引擎中集成 ...