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. tar 分卷压缩和解压缩

    示例将 jdk1.8.0_221 文件夹按 98m 进行分卷压缩和解压缩压缩: tar -czvf - jdk1.8.0_221/ |split -b 98m - jdk1.8.0_221.tar.g ...

  2. docker 1.13版本修改默认存储路径及添加私有registry

    1.服务器安装dockeryum install docker -y12.修改配置文件方法1: 编辑 `/etc/sysconfig/docker`文件 修改`OPTION`选项 添加 --insec ...

  3. #渗透测试 kioptix level 2靶机通关教程及提权

    声明! 文章所提到的网站以及内容,只做学习交流,其他均与本人以及泷羽sec团队无关,切勿触碰法律底线,否则后果自负!!!! 工具链接:https://pan.quark.cn/s/530656ba55 ...

  4. Qt/C++音视频开发81-采集本地麦克风/本地摄像头带麦克风/桌面采集和麦克风/本地设备和桌面推流

    一.前言 随着直播的兴起,采集本地摄像头和麦克风进行直播推流,也是一个刚需,最简单的做法是直接用ffmpeg命令行采集并推流,这种方式简单粗暴,但是不能实时预览画面,而且不方便加上一些特殊要求.之前就 ...

  5. Qt开源作品12-硬盘容量控件

    一.前言 磁盘容量统计控件,说白了,就是用来统计本地盘符占用的容量,包括但不限于已用空间.剩余空间.总大小.已用百分比等,其中对应的百分比采用进度条显示,该进度条的前景色和背景色及文字颜色可以设置,在 ...

  6. Type of the default value for 'data' prop must be a function的解决方法

    Type of the default value for 'data' prop must be a function的解决方法 问题现象 在写形如prop: {type: Array; defau ...

  7. MySql中的driverClassName、url

    在Java桌面开发或者Java Web开发(基于SSM框架)配置MySQL数据源时,driverClassName属性如果填错了,会导致了这一系列错误.归结其原因就是 mysql-connector- ...

  8. IM跨平台技术学习(十一):环信基于Electron打包Web IM桌面端的技术实践

    本文由环信技术黄飞鹏分享,原题"实战|如何利用 Electron 快速开发一个桌面端应用",本文进行了排版和内容优化等. 1.引言 早就听说利用Electron可以非常便捷的将网页 ...

  9. Windows安全加固(二)

    三.本地安全策略用户权限分配 1. 使用windows+R打开运行,输入"secpol.msc"打开本地安全策略->本地策略->用户权限分配->找到"拒 ...

  10. .NET 开发的分流抢票软件,不做广告、不收集隐私

    前言 每年春节大家必备的抢票工具Bypass-分流抢票.分流抢票是一款免费无广适用于PC端的自动分流抢票软件. 分流抢票,是以用户为中心.人性化的抢票软件.不做广告.不做推广.不携带病毒.不收集隐私信 ...