比赛链接:https://codeforces.com/contest/1421

A. XORwice

题意

给出两个正整数 \(a、b\),计算 \((a \oplus x) + (b \oplus x)\) 的最小值。

题解

\[\begin{equation} a+b = a \oplus b + ((a\ \&\ b)<<1) \end{equation}
\]
\[\begin{equation} (a \oplus x) + (b \oplus x) = ((a \oplus x) \oplus (b \oplus x)) + (((a \oplus x)\ \& \ (b \oplus x))<<1) \end{equation}
\]
\[\ \ \ \ \ \ \ \ \ \ = (a \oplus b) + (((a \oplus x)\ \&\ (b \oplus x))<<1)
\]

显然存在 \(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】的更多相关文章

  1. Codeforces Round #682 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1438 A. Specific Tastes of Andre 题意 构造一个任意连续子数组元素之和为子数组长度倍数的数组. ...

  2. Codeforces Round #678 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1436 A. Reorder 题解 模拟一下这个二重循环发现每个位置数最终都只加了一次. 代码 #include <bi ...

  3. Codeforces Round #675 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1422 A. Fence 题意 给出三条边 $a,b,c$,构造第四条边使得四者可以围成一个四边形. 题解 $d = max( ...

  4. Codeforces Round #668 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1405 A. Permutation Forgery 题意 给出一个大小为 $n$ 的排列 $p$,定义 \begin{equ ...

  5. Codeforces Round #732 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1546 A. AquaMoon and Two Arrays 题意 给出两个大小为 \(n\) 的数组 \(a, b\) ,每 ...

  6. Codeforces Round #677 (Div. 3)【ABCDE】

    比赛链接:https://codeforces.com/contest/1433 A. Boring Apartments 题解 模拟即可. 代码 #include <bits/stdc++.h ...

  7. Codeforces Round #382 Div. 2【数论】

    C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...

  8. Codeforces Round #684 (Div. 2)【ABC1C2】

    比赛链接:https://codeforces.com/contest/1440 A. Buy the String 题解 枚举字符串中 \(0\) 或 \(1\) 的个数即可. 代码 #includ ...

  9. Codeforces Round #658 (Div. 2)【ABC2】

    做完前四题还有一个半小时... 比赛链接:https://codeforces.com/contest/1382 A. Common Subsequence 题意 给出两个数组,找出二者最短的公共子序 ...

随机推荐

  1. #2使用html+css+js制作网站教程 测试

    #2使用html+css+js制作网站教程 测试 本系列链接 1 测试 1.1 运行 1.2 审查 1.3 审查技巧 1.4 其他 引言: 编写完代码后就要上机测试代码,获得用户体验,筛选bug 笔者 ...

  2. 在微信小程序开发中使用Typescript

    Typescript的优势咱不需要赘述太多,有兴趣可以参考(https://www.typescriptlang.org/).今天给大家分享一下如何在微信小程序(或者其他同类小程序)开发中使用Type ...

  3. nginx文件结构与解析,例子

    1.nginx文件结构 1 ... #全局块 2 3 events { #events块 4 ... 5 } 6 7 http #http块 8 { 9 ... #http全局块 10 server ...

  4. 【C++】《C++ Primer 》第二章

    第二章 变量和基本类型 指针和引用的不同点 引用不是一个对象,它没有实际地址,但是指针是一个对象.允许对指针赋值和拷贝,而且在指针的生命周期内它可以先后指向几个不同的对象. 指针无须在定义时赋初值.

  5. 使用axis1.4生成webservice的客户端代码

    webservice服务端: https://blog.csdn.net/ghsau/article/details/12714965 跟据WSDL文件地址生成客服端代码: 1.下载 axis1.4 ...

  6. 1.8V转5V电平转换芯片,1.8V转5V的电源芯片

    1.8V是一个比较低的电压,在电压供电电压中,1.8V电压的过于小了,在一些电子模块或者MCU中,无法达到供电电压,和稳压作用,PW5100就是可以在1.8V转5V的电平转换电路和芯片,最大可提供50 ...

  7. Typora+PicGo+Gitee打造图床

    前言 ​ 自己一直使用的是Typora来写博客,但比较麻烦的是图片粘贴上去后都是存储到了本地,写好了之后放到博客园等地,图片不能直接访问,但如今Typora已经支持图片上传,所以搞了一波图片上传到Gi ...

  8. 开源AwaitableCompletionSource,用于取代TaskCompletionSource

    1 TaskCompletionSource介绍 TaskCompletionSource提供创建未绑定到委托的任务,任务的状态由TaskCompletionSource上的方法显式控制,以支持未来的 ...

  9. SQL Server 邮箱告警配置

    目录 配置数据库邮件 * 手动启用数据库邮件功能 * 配置数据库邮件 * 测试数据库邮件 实现 JOB 任务运行状态的检测 * 定义操作员 * 新建死锁警报 * 设置 SQL Server 代理 创建 ...

  10. Linux文件系统之INode

    本文转载自阮一峰博客:理解inode 一.inode是什么? 理解inode,要从文件储存说起. 文件储存在硬盘上,硬盘的最小存储单位叫做"扇区"(Sector).每个扇区储存51 ...