Codeforces Round 1006 (Div. 3) 补题+题解
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) 补题+题解的更多相关文章
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #833 (Div. 2)补题
Codeforces Round #833 (Div. 2) D. ConstructOR 知识点:高位和对低位无影响 一开始以为和广州的M一样,是数位dp,后来发现只要找到一个就行 果然无论什么时候 ...
- 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 ...
- Codeforces Round #585 (Div. 2) [补题]
前言 2019.9.16 昨天下午就看了看D题,没有写对,因为要补作业,快点下机了,这周争取把题补完. 2019.9.17 这篇文章或者其他文章难免有错别字不被察觉,请读者还是要根据意思来读,不要纠结 ...
- Codeforces Round #429 (Div. 2) 补题
A. Generous Kefa 题意:n个气球分给k个人,问每个人能否拿到的气球都不一样 解法:显然当某种气球的个数大于K的话,就GG了. #include <bits/stdc++.h> ...
- Codeforces Round #579 (Div. 3) 套题 题解
A. Circle of Students 题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
- Codeforces Round #615 (Div. 3) 补题记录
第一次搞CF,结果惨不忍睹...还是太菜了 A:要用到全部的钱,所以总数必须是3的倍数,而且初始状态下任意一人的钱数不能超过总数除以3,否则没法分了 (也就这个签到算是在我能力范围之内了....) # ...
- Codeforces Round #617 (Div. 3) 补题记录
1296A - Array with Odd Sum 题意:可以改变数组中的一个数的值成另外一个数组中的数,问能不能使数组的和是个奇数 思路:签到,如果本来数组的和就是个奇数,那就OK 如果不是,就需 ...
- Codeforces Round #741 (Div. 2)部分题题解
我果然还是太菜了,就写了两道题....真是水死了.... A The Miracle and the Sleeper 简化题意:给定\(l,r\),求\(a\)%\(b\)的最大值,其中\(r> ...
- Codeforces Round #786 (Div. 3) 补题记录
小结: A,B,F 切,C 没写 1ll 对照样例才发现,E,G 对照样例过,D 对照样例+看了其他人代码(主要急于看后面的题,能调出来的但偷懒了. CF1674A Number Transforma ...
随机推荐
- Flutter之GetX之Obs
Flutter之GetX之Obs 除了之前说过的GetBuilder,GetX还有其他的状态管理方式 一个后缀就可以把一个变量变得可观察,变量每次改变的时候,使用它的小部件就会被更新 var name ...
- 知乎 微软当年的 J++ 究竟是什么?为什么 Sun 要告它? zz
https://www.zhihu.com/question/22814456 考个古
- drf知识点
目录 drf知识点 1.web应用模式.API接口.接口测试工具postman.restful规范 2.序列化与反序列化的概念.基于django原生编写5个接口.drf介绍和快速使用.cbv源码分析 ...
- Zookeeper Java API操作流程
首先需要配置一台Zookeeper服务器 pom文件 <dependencies> <!-- https://mvnrepository.com/artifact/org.a ...
- 【Python】数据分析与可视化实践:收支日统计数据可视化的实现
Python数据分析与可视化实践:收支日统计数据可视化的实现 Author:萌狼蓝天 Date:2023-5-7 数据读入与基本处理 上图是原始数据的一部分,存放于excel中,首先使用pd读入数据. ...
- 【Web前端】【JavaScript】实现表格隔行变色
方法1:原生JavaScript 设置CSS table td{ border:red solid 1px; } .tr1{ color:white; background: black; } .tr ...
- 利用shell中awk和xargs以及sed将多行多列文本中某一列合并成一行
一.问题描述最近需要利用Shell将多行多列文本中某一列,通过指定的分隔符合并成一行.假设需要处理的文本如下: 我们主要处理的是,将用户名提取处理,合并成一行,并通过逗号进行分隔.最终的格式如下: & ...
- Spring Boot 2.4 中文
Spring Boot 2.4 中文 https://runebook.dev/zh-CN/docs/spring_boot/spring-boot-features
- 【转载】 利用p6spy拦截并查看数据库执行操作
https://blog.csdn.net/fanxiaobin577328725/article/details/71601760 一.简介 项目首 页:http://p6spy.github.io ...
- Qt开源作品10-代码统计组件
一.前言 代码行数统计主要用来统计项目中的所有文件的代码行数,其中包括空行.注释行.代码行,可以指定过滤拓展名,比如只想统计.cpp的文件,也可以指定文件或者指定目录进行统计.写完这个工具第一件事情就 ...