Codeforces Round #676 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1421
A. XORwice
题意
给出两个正整数 \(a、b\),计算 \((a \oplus x) + (b \oplus x)\) 的最小值。
题解
\]
\]
\]
显然存在 \(x\)(事实上 \(x = a\ \& \ b\))使得 \(((a \oplus x)\ \& \ (b \oplus x)) = 0\) 。
所以 \((a \oplus x) + (b \oplus x) \ge a \oplus b\) 。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
cout << (a ^ b) << "\n";
}
return 0;
}
B. Putting Bricks in the Wall
题意
有一个 \(01\) 方阵,起点和终点分别位于左上角和右下角,每次只能选择一条 \(0\) 路径或 \(1\) 路径到达终点。
现在要使起点终点不连通,最多可以反转两个方格,输出任一方案。
题解
如果不能连通,最简单的方案就是使得左上角和右下角相邻四个方块的状态为 \(0011\) 或 \(1100\) 。
所以枚举两种状态,如果需要更改的次数小于等于 \(2\) 输出即可。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<string> MP(n);
for (auto &x : MP) cin >> x;
string s;
(((s += MP[0][1]) += MP[1][0]) += MP[n - 2][n - 1]) += MP[n - 1][n - 2];
for (string t : {"0011", "1100"}) {
vector<pair<int, int>> v;
if (s[0] != t[0]) v.emplace_back(1, 2);
if (s[1] != t[1]) v.emplace_back(2, 1);
if (s[2] != t[2]) v.emplace_back(n - 1, n);
if (s[3] != t[3]) v.emplace_back(n, n - 1);
if (v.size() <= 2) {
cout << v.size() << "\n";
for (auto [x, y] : v) cout << x << ' ' << y << "\n";;
break;
}
}
}
return 0;
}
C. Palindromifier
题意
给出一个字符串 \(s_1s_2 \dots s_{n-1}s_n\),每次操作有两种选择:
- 将 \(s_2s_3 \dots s_i(i \le n-1)\) 反转后添加到字符串左侧
- 将 \(s_is_{i+1} \dots s_{n-1}(i \ge 2)\) 反转后添加到字符串右侧
最多操作 \(30\) 次,给出使得字符串为回文字符串的操作过程。
题解
以某一端为对称中心构造即可。
如:12345 就以 5 为中心对称构造
12345
212345
2123454321
21234543212
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
cout << 3 << "\n";
cout << 'L' << ' ' << 2 << "\n";
cout << 'R' << ' ' << 2 << "\n";
cout << 'R' << ' ' << 2 * s.size() - 1 << "\n";
return 0;
}
D. Hexagons
题意
给出:
- \(x+1\) 的花费 \(c_6\)
- \(x+1,\ y+1\) 的花费 \(c_1\)
- \(y+1\) 的花费 \(c_2\)
- \(x-1\) 的花费 \(c_3\)
- \(x-1,\ y-1\) 的花费 \(c_4\)
- \(y-1\) 的花费 \(c_5\)
计算从 \((0,0)\) 走到 \((x,y)\) 的最小花费。
题解
计算一下六个方向的最小花费,然后分类讨论即可。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
long long x, y;
cin >> x >> y;
long long c1, c2, c3, c4, c5, c6;
cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
c1 = min(c1, c2 + c6);
c2 = min(c2, c1 + c3);
c3 = min(c3, c2 + c4);
c4 = min(c4, c3 + c5);
c5 = min(c5, c4 + c6);
c6 = min(c6, c1 + c5);
if (x >= 0 and y >= 0) {
if (x > y)
cout << y * c1 + (x - y) * c6 << "\n";
else
cout << x * c1 + (y - x) * c2 << "\n";
} else if (x <= 0 and y <= 0) {
if (x > y)
cout << -x * c4 + (x - y) * c5 << "\n";
else
cout << -y * c4 + (y - x) * c3 << "\n";
} else if (x >= 0 and y <= 0) {
cout << x * c6 - y * c5 << "\n";
} else if (x <= 0 and y >= 0) {
cout << -x * c3 + y * c2 << "\n";
}
}
return 0;
}
Codeforces Round #676 (Div. 2)【ABCD】的更多相关文章
- Codeforces Round #682 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1438 A. Specific Tastes of Andre 题意 构造一个任意连续子数组元素之和为子数组长度倍数的数组. ...
- Codeforces Round #678 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1436 A. Reorder 题解 模拟一下这个二重循环发现每个位置数最终都只加了一次. 代码 #include <bi ...
- Codeforces Round #675 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1422 A. Fence 题意 给出三条边 $a,b,c$,构造第四条边使得四者可以围成一个四边形. 题解 $d = max( ...
- Codeforces Round #668 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1405 A. Permutation Forgery 题意 给出一个大小为 $n$ 的排列 $p$,定义 \begin{equ ...
- Codeforces Round #732 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1546 A. AquaMoon and Two Arrays 题意 给出两个大小为 \(n\) 的数组 \(a, b\) ,每 ...
- Codeforces Round #677 (Div. 3)【ABCDE】
比赛链接:https://codeforces.com/contest/1433 A. Boring Apartments 题解 模拟即可. 代码 #include <bits/stdc++.h ...
- Codeforces Round #382 Div. 2【数论】
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...
- Codeforces Round #684 (Div. 2)【ABC1C2】
比赛链接:https://codeforces.com/contest/1440 A. Buy the String 题解 枚举字符串中 \(0\) 或 \(1\) 的个数即可. 代码 #includ ...
- Codeforces Round #658 (Div. 2)【ABC2】
做完前四题还有一个半小时... 比赛链接:https://codeforces.com/contest/1382 A. Common Subsequence 题意 给出两个数组,找出二者最短的公共子序 ...
随机推荐
- 基于腾讯云存储COS的ClickHouse数据冷热分层方案
一.ClickHouse简介 ClickHouse是一个用于联机分析(OLAP)的列式数据库管理系统(DBMS),支持PB级数据量的交互式分析,ClickHouse最初是为YandexMetrica ...
- Wi-Fi 6 与 5G 相比哪个更快?
随着 iPhone12 的发布,iOS 系统正式开始拥抱 5G,智能手机全面进入了 5G 时代.伴随着各大运营商的 5G 推广以及相关基站建设的如火如荼,5G 成了大家广泛讨论的热门词汇.这样热门的光 ...
- 百度智能(文本识别),API传图OC代码与SDK使用
百度智能中的文本识别中的身份证识别,有API方式和SDK方式 API方式 百度智能(文本识别),百度API传图没有提供OC的示例,这里提供一下 - (void)OCTest:(NSString*)to ...
- scaffoldingTools
脚手架工具 脚手架工具概要(前端工程化的发起者) 脚手架的本质作用:创建项目基础架构.提供项目规范和约定 相同的组织结构 相同的开发规范 相同的模块依赖 相同的工具配置 相同的基础代码 举例:IDE创 ...
- 通过trace分析优化其如何选择执行计划
mysql5.6提供了对sql的跟踪trace,通过trace文件能够进一步了解为什么优化其选择执行计划a而不选b执行计划,帮助我们更好的理解优化其的行为. 使用方式:首先打开trace,设置格式为j ...
- 软碟通制作win10镜像,无法打开install.wim的问题
打开软碟通,单击左上角"文件"→"打开",选择.iso文件的存放目录,再选择.iso映像文件打开,即可看到映像文件全部加载到UltraISO了,如下图. 将 ...
- CTFHub - Web(三)
密码口令: 弱口令: 1.随意输入账号密码,抓包, 2.右击,"Send to Intruder",打开选项卡Intruder,点击position,椭圆框处软件已经自动为我们把要 ...
- buuctf刷题之旅—web—随便注
打开环境 根据提示应该是sql注入 查看数据库名,和数据表 1';show databases;# 1';show tables;# 查看表内字段(1';desc `1919810931114514` ...
- Empire
Empire 内网渗透神器 一 基本渗透 安装 git clone https://github.com/BC-SECURITY/Empire/ ./setup/install.sh 启动 ./emp ...
- [Usaco2007 Dec]Building Roads 修建道路
题目描述 Farmer John最近得到了一些新的农场,他想新修一些道路使得他的所有农场可以经过原有的或是新修的道路互达(也就是说,从任一个农场都可以经过一些首尾相连道路到达剩下的所有农场).有些农场 ...