补题链接: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. OpenSSL 使用AES对文件加解密

    AES(Advanced Encryption Standard)是一种对称加密算法,它是目前广泛使用的加密算法之一.AES算法是由美国国家标准与技术研究院(NIST)于2001年发布的,它取代了原先 ...

  2. SQL执行insert into后返回主键ID

    1 select @@identity 2 select SCOPE_IDENTITY() 3 select IDENT_CURRENT('table') 注解:@@IDENTITY 返回当前会话的所 ...

  3. 【UniApp】-uni-app-扩展组件

    前言 好,经过上个章节的介绍完毕之后,了解了一下 uni-app-内置组件 那么了解完了uni-app-内置组件之后,这篇文章来给大家介绍一下 UniApp 中的扩展组件 首先不管三七二十一,先来新建 ...

  4. 【译】Visual Studio 17.8 中我最喜欢的特性

    对于 Visual Studio 团队来说,这是忙碌的一周,他们准备了 Ignite 和 .NET Conf,并发布了最新版本的 Visual Studio 2022,即17.8版本.有很多很酷的新功 ...

  5. catcat-new【目录穿透+特殊文件】

    catcat-new[目录穿透+特殊文件] 题目界面 点击任何一只猫猫,发现路径泄露: 解题步骤 测试目录遍历漏洞 路径: ?file=../../../../etc/passwd 成功读取到pass ...

  6. Oracle参数文件spfile

    spfile:server parameter file. spfile只能通过OEM(oracle enterprise manager)软件或者alter system命令进行修改. spfile ...

  7. 解析RC4加密算法

    一.简介 RC4(Rivest Cipher 4)是一种对称加密算法,由Ronald L. Rivest于1987年为其所在的公司RSA Data Security Inc. 开发.作为一种可变密钥长 ...

  8. Using PostMessage/SendMessage to send keys to c# IE WebBrowser

    [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool PostM ...

  9. 年底了,网站被挂马了,关于IIS被陌生DLL劫持(新人发帖,写的不好的地方,请多多担待)

    一上班被分到两个需要杀毒的站点,情况是SEO被劫持 出现一些博彩信息,但是打开确实正常内容,使用站长工具的网站被黑检测功能,发现网站的HEAD前面加载一对加密的东西 一开始我使用D盾扫描网站,删除了一 ...

  10. linux内核initcall放置在各个section中函数执行流程

    前言 linux以及嵌入式一些代码,我们看到core_initcall.device_initcall等等需要链接器分配各个section,并且在启动该模块时候执行.下面我们详细追溯一下执行过程. 作 ...