A. New World, New Me, New Array

贪心的想每次都赋值一个 \(p\) 如果正好和为 \(k\) 则答案就是 \(k/p\) ,否则是 \(k/p+1\)。

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10; void solve() {
int n, k, p;
cin >> n >> k >> p;
if (n * p < abs(k)) {
cout << -1 << '\n';
return;
}
int ans = abs(k / p);
if (k % p != 0) ans++;
cout << ans << '\n';
} signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
}

B. Having Been a Treasurer in the Past, I Help Goblins Deceive

简单地想,\(O(n)\) 扫描一遍记录前后各放多少个 "-" 会使子序列最多,直接计算即可。

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10; void solve() {
string s;
int n;
cin >> n;
cin >> s;
int cnt = 0, cnt1 = 0;
for (auto t : s) {
if (t == '-') cnt++;
}
int mx = 0;
cnt1 = s.size() - cnt;
for (int i = 1; i <= cnt; i++) {
int x = i, y = cnt - i;
mx = max(mx, x * y);
}
cout << mx*cnt1 << '\n';
} signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
}

C. Creating Keys for StORages Has Become My Main Skill

贪心 ,\([0,n-1]\) 尽可能取,维护或值,如果恰好为 \(x\) 则是答案。否则尽可能修改大的将最后一项取为 \(x\),这样 \(MEX\) 最大。

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10; void solve() {
int n, x;
cin >> n >> x;
int now = 0;
vector<int> ans(n+10, 0);
for (int i = 1; i < n; i ++ ) {
if ((x | i) == x) {
ans[i] = i;
now |= i;
}
}
if (now != x) {
ans[n - 1] = x;
}
for (int i = 0; i < n; i ++ ) {
cout << ans[i] << ' ';
}
cout << '\n';
} signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
}

D. For Wizards, the Exam Is Easy, but I Couldn't Handle It

很明显反转数的个数变化只与选择的区间有关,与区间外的数无关,区间的贡献则是区间中小于 \(l\) 的个数减去大于 \(l\) 的个数 。

\(n^2\) 暴力枚举,在过程中记下 \([l,r]\) 区间中大于 \(l\) 和小于 \(l\) 的个数,然后统计贡献最大的区间便是答案。

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10; void solve() {
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = 0;
pair<int, int> anss;
for (int l = 1; l <= n; l++) {
int x = 0, y = 0;
for (int r = l; r <= n; r++) {
if (a[r] > a[l]) x++;
if (a[r] < a[l]) y++;
if (y - x >= ans) {
ans = y - x;
anss.first = l, anss.second = r;
}
}
}
cout << anss.first << ' ' << anss.second << '\n';
} signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
}

E. Do You Love Your Hero and His Two-Hit Multi-Target Attacks?

大致题意:Akito需要在坐标系中放置\(n\) 根法杖,且这些法杖的位置必须是不同的整数坐标点。放置后,恰好有\(k\) 对法杖位于同一条水平线或垂直线上。

构造题,利用组合数的知识 \(C(x,2)\) 尽可能构造即可。

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10; void solve() {
int n;
cin >> n;
if (n == 0) {
cout << "2\n0 0\n1 1\n";
return;
}
vector<pair<int, int>> ans;
int yu = n;
int ls = 1, d = 0;
while (yu > 2) {
for (int i = 2; i <= 500; i++) {
int x = (i - 1) * i / 2;
if (x > yu) {
int res = (i - 1) * (i - 2);
yu -= res / 2;
for (int j = ls; j <= ls + i - 1 - 1; j++) {
ans.push_back({-j, d});
}
ls = ls + i - 1;
d -= 1;
break;
}
}
}
if (yu == 2) {
ans.push_back({1, 1});
ans.push_back({2, 1});
ans.push_back({3, 2});
ans.push_back({4, 2});
} else if (yu == 1) {
ans.push_back({1, 1});
ans.push_back({2, 1});
}
cout << ans.size() << '\n';
for (pair<int, int> p : ans) {
cout << p.first << ' ' << p.second << '\n';
}
} signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
}

F. Goodbye, Banker Life

打表找一下规律可以发现第 \(n\) 行是由最近的第 \(n-2^x\) 行转移过来的,那么很明显可以递归,通过递归记录一下答案,处理一下直接输出。代码实现比较抽象,具体看代码。

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int n, x;
int ksm(int x, int y) {
int ans = 1;
while (y) {
if (y & 1)
ans = ans * x;
y >>= 1;
x = x * x;
}
return ans;
}
vector<int> po;
void init() {
for (int i = 32; i >= 0; i--) {
int x = ksm(2, i);
po.push_back(x);
}
}
deque<pair<string, int>> de;
void dfs(int u) {
if (u == 1 || (u & (u - 1)) == 0) {
if (u == 1) {
de.push_front({"1", 1});
} else {
de.push_back({"1", u});
}
return;
}
for (int i = 0; i < 32; i++) {
if (po[i] <= u) {
dfs(u - po[i]);
int yu = u - 2 * (u - po[i]);
de.push_back({"0", yu});
de.push_back({"x", 0});
return;
}
}
}
void pr();
void pr1(int l, int r);
void pr0(int l, int r);
void solve() {
while (de.size()) de.pop_front();
cin >> n >> x;
string s = to_string(1);
for (int i = 0; i < 32; i++) {
if (n == po[i]) {
pr();
return;
}
}
dfs(n);
vector<pair<string, int>> p;
while (de.size()) {
pair<string, int> it = de.front();
de.pop_front();
p.push_back(it);
}
for (int i = 0; i < p.size(); i++) {
string a = p[i].first;
int b = p[i].second;
if (a == "0") {
pr0(1, b);
}
else if (a == "1") {
pr1(1, b);
}
else if (a == "x") {
int len = 0;
if (p[i - 1].first == "0") len = i - 1;
else len = i;
string lp = "";
for (int j = 0; j < len; j++) {
int cnt = p[j].second;
if (p[j].first == "0")
for (int k = 1; k <= cnt; k++) {
cout << 0 << ' ';
lp += "0";
}
else if (p[j].first == "1") {
for (int k = 1; k <= cnt; k++) {
cout << x << ' ';
lp += "1";
}
}
else
for (char t : p[j].first) {
if (t == '1') cout << x << ' ', lp += "1";
else if (t == '0') cout << 0 << ' ', lp += "0";
}
}
p[i].first = lp;
}
}
cout << '\n';
}
void pr() {
for (int i = 1; i <= n; i++)
cout << x << ' ';
cout << '\n';
}
void pr1(int l, int r) {
for (int i = l; i <= r; i++) cout << x << ' ';
}
void pr0(int l, int r) {
for (int i = l; i <= r; i++) cout << 0 << ' ';
} signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
init();
cin >> t;
while (t--)
solve();
}
/*
第 1 行: 1
第 2 行: 1 1
第 3 行: 1 0 1
第 4 行: 1 1 1 1
第 5 行: 1 0 0 0 1
第 6 行: 1 1 0 0 1 1
第 7 行: 1 0 1 0 1 0 1
第 8 行: 1 1 1 1 1 1 1 1
第 9 行: 1 0 0 0 0 0 0 0 1
第 10行: 1 1 0 0 0 0 0 0 1 1
*/

Codeforces Round 1006 (Div. 3) 补题+题解的更多相关文章

  1. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  2. Codeforces Round #833 (Div. 2)补题

    Codeforces Round #833 (Div. 2) D. ConstructOR 知识点:高位和对低位无影响 一开始以为和广州的M一样,是数位dp,后来发现只要找到一个就行 果然无论什么时候 ...

  3. Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring

    D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  4. Codeforces Round #585 (Div. 2) [补题]

    前言 2019.9.16 昨天下午就看了看D题,没有写对,因为要补作业,快点下机了,这周争取把题补完. 2019.9.17 这篇文章或者其他文章难免有错别字不被察觉,请读者还是要根据意思来读,不要纠结 ...

  5. Codeforces Round #429 (Div. 2) 补题

    A. Generous Kefa 题意:n个气球分给k个人,问每个人能否拿到的气球都不一样 解法:显然当某种气球的个数大于K的话,就GG了. #include <bits/stdc++.h> ...

  6. Codeforces Round #579 (Div. 3) 套题 题解

    A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...

  7. Codeforces Round #615 (Div. 3) 补题记录

    第一次搞CF,结果惨不忍睹...还是太菜了 A:要用到全部的钱,所以总数必须是3的倍数,而且初始状态下任意一人的钱数不能超过总数除以3,否则没法分了 (也就这个签到算是在我能力范围之内了....) # ...

  8. Codeforces Round #617 (Div. 3) 补题记录

    1296A - Array with Odd Sum 题意:可以改变数组中的一个数的值成另外一个数组中的数,问能不能使数组的和是个奇数 思路:签到,如果本来数组的和就是个奇数,那就OK 如果不是,就需 ...

  9. Codeforces Round #741 (Div. 2)部分题题解

    我果然还是太菜了,就写了两道题....真是水死了.... A The Miracle and the Sleeper 简化题意:给定\(l,r\),求\(a\)%\(b\)的最大值,其中\(r> ...

  10. Codeforces Round #786 (Div. 3) 补题记录

    小结: A,B,F 切,C 没写 1ll 对照样例才发现,E,G 对照样例过,D 对照样例+看了其他人代码(主要急于看后面的题,能调出来的但偷懒了. CF1674A Number Transforma ...

随机推荐

  1. 中电金信:源启混沌工程平台(V4)与东方通TongwebV7.0完成适配认证

    ​近日,源启混沌工程平台(V4)与北京东方通科技股份有限公司(以下简称东方通)应用服务器软件东方通TongwebV7.0完成产品兼容互认证,通过在产品功能.性能.兼容性方面的全面严格测试,得出结论:东 ...

  2. 在 K8S 中创建 Pod 是如何使用到 GPU 的: nvidia device plugin 源码分析

    本文主要分析了在 K8s 中创建一个 Pod 并申请 GPU 资源,最终该 Pod 时怎么能够使用 GPU 的,具体的实现原理,以及 device plugin.nvidia-container-to ...

  3. [sa-token]StpUtil.getLoginId

    闲聊 一般情况下,我们想用uid,可能需要前端将uid传过来,或者将token传来,然后我们进行识别. 用了sa-token之后,可以使用StpUtil.getLoginId()方法获取当前会话的用户 ...

  4. kubectl cp

    简介 将文件.目录复制到容器:或从容器复制文件.目录. kubectl cp <file-spec-src> <file-spec-dest> 示例 # !!!重要提示!!! ...

  5. linux tc命令进行网络限速、丢包、延迟设置(简单使用)

    linux自带tc命令版本不是很低的linux系统都自带tc如果你的系统不带这个命令,建议使用类似括号中的命令进行安装 (yum -y install iproute) TC 中使用下列的缩写表示相应 ...

  6. logback高级特性使用(二) 自定义Pattern模板

    原文链接:https://blog.csdn.net/chenjie2000/article/details/8892764 创建自定义格式转换符有两步: 1.写一个转换器类,继承ClassicCon ...

  7. 如何控制bean的加载顺序?

    写在前面 springboot遵从约定大于配置的原则,极大程度的解决了配置繁琐的问题.在此基础上,又提供了spi机制,用spring.factories可以完成一个小组件的自动装配功能. 在一般业务场 ...

  8. Qt项目升级到Qt6吐血经验总结

    Qt的版本发布越来越频繁,Qt6发布已经有一段时间了,越来越多的人咨询之前的代码是否可以增加对Qt6的支持,包括开源的项目QWidgetDemo(一年时间超过2.6K star),近期百忙之中,对所有 ...

  9. C# WinForm 托盘程序

    实现步骤 创建 NotifyIcon 控件并设置属性: 编写 NotifyIcon 响应控制事件: 在主窗体的Load事件中将 NotifyIcon 添加到系统托盘: 程序退出时,移除系统托盘的 No ...

  10. G1原理—4.G1垃圾回收的过程之Young GC

    大纲 1.G1的YGC过程 2.YGC并行处理阶段的过程 3.YGC串行处理阶段的过程(一) 4.YGC串行处理阶段的过程(二) 5.整个YGC的执行流程总结 1.G1的YGC过程 (1)YGC相关的 ...