Codeforces Round #742 (Div. 2) 个人题解
A. Domino Disaster
2分钟签到
#include <bits/stdc++.h>
#define fors(i, a, b) for(int i = (a); i <= (b); ++i)
#define lson k<<1
#define rson k<<1|1
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define mem(a) memset(a, 0, sizeof(a))
#define DDLC_ESCAPE_PLAN_FAILED ios::sync_with_stdio(false), cin.tie(0)
#define int long long
const int inf = 0x3f3f3f3f;
const double dinf = 1e100;
typedef long long ll;
//const ll linf = 9223372036854775807LL;
// const ll linf = 1e18;
using namespace std;signed main()
{DDLC_ESCAPE_PLAN_FAILED;int t;cin >> t;while(t--){int n;cin >> n;string s;cin >> s;for(auto x : s){if(x == 'U') cout << 'D';else if(x == 'D') cout << 'U';else cout << x;}cout << endl;}return 0;
}
B. MEXor Mixup
题意
现在有一个未定数组,它的MexMexMex是aaa, 它所有元素的异或和是bbb,问这个数组最少有几个元素。(0<a≤3e5,0≤b≤5e4)(0<a\leq 3e5,0\leq b\leq 5e4)(0<a≤3e5,0≤b≤5e4).
分析
由于Mex=aMex=aMex=a,故[0,a−1][0,a-1][0,a−1]必定出现。
讨论特殊情况:当a=1,b=0a=1,b=0a=1,b=0,这个数组是{0}\{0\}{0},共一个元素。也就是说若异或和就是bbb,那一共就是aaa个元素。
其余的情况,首先我们对[0,a−1][0,a-1 ][0,a−1]做异或和,得出来一个数xxx。此时我们可以再取一个数yyy,使得x⨁y=bx\bigoplus y = bx⨁y=b. 但是要注意,这个yyy可能就是aaa. 根据异或的性质——x⨁y=z⇔x⨁z=yx\bigoplus y = z \Harr x \bigoplus z = yx⨁y=z⇔x⨁z=y.
故我们可以求出y=x⨁by=x\bigoplus by=x⨁b. 如果求出来的 yyy 和 aaa 不相等,那么我们的数组就是[0,a−1][0,a-1][0,a−1]加上 yyy,共 a+1a + 1a+1 个元素;如果y==ay==ay==a,那么我们不可以直接给数组加上aaa,但一定可以通过另外两个不等于aaa的数作异或得到aaa,故数组共a+2a+2a+2个元素。
由于题目数据限制,每次直接算异或和会超时,记得预处理前缀和。
代码
#include <bits/stdc++.h>
#define fors(i, a, b) for(int i = (a); i <= (b); ++i)
#define lson k<<1
#define rson k<<1|1
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define mem(a) memset(a, 0, sizeof(a))
#define DDLC_ESCAPE_PLAN_FAILED ios::sync_with_stdio(false), cin.tie(0)
#define int long long
const int inf = 0x3f3f3f3f;
const double dinf = 1e100;
typedef long long ll;
//const ll linf = 9223372036854775807LL;
// const ll linf = 1e18;
using namespace std;
const int maxn = 3e5 + 10;
int pre[maxn];
signed main()
{DDLC_ESCAPE_PLAN_FAILED;int t;cin >> t;pre[0] = 0;fors(i, 1, maxn - 1) pre[i] = (pre[i - 1] ^ i);while(t--){int a, b;cin >> a >> b;if(a == 1 && b == 0){cout << 1 << endl;}else{int sum = pre[a - 1];if(sum == b) cout << a << endl;else if((sum ^ a) == b) cout << a + 2 << endl;else cout << a + 1 << endl;}}return 0;
}
C. Carring Condrum
题意
作有着错误进位方式的竖式运算,每次遇到进位都会进两位而不是进一位。例如1+91+91+9,进位得到的1会放在百位而不是十位。
现在给出一个数nnn,问有多少对有序数对(a,b)(a,b)(a,b),0<a,b<n0<a,b<n0<a,b<n,在经过这种错误运算方式之后会得到nnn.
分析
因为每次都进两位,故奇数位和偶数位之间互相不影响,可以把它们分开来看。
例如,2021这个数,我们可以拆成22和1.
其中,加和得到22的有序数对共23对(aaa从000到222222),加和得到1的有序数对共2对。把这奇偶的方法合并,那么总共有23×2=4623×2=4623×2=46个数对。
但是,由于2021这个数不能拆成(0,2021)(0,2021)(0,2021)和(2021,0)(2021,0)(2021,0),所以要减去2个,最终答案是44.
所以,若拆分后奇数位数字是xxx,偶数位的是yyy,答案显然是(x+1)(y+1)−2(x+1)(y+1)-2(x+1)(y+1)−2.
代码
#include <bits/stdc++.h>
#define fors(i, a, b) for(int i = (a); i <= (b); ++i)
#define lson k<<1
#define rson k<<1|1
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define mem(a) memset(a, 0, sizeof(a))
#define DDLC_ESCAPE_PLAN_FAILED ios::sync_with_stdio(false), cin.tie(0)
#define int long long
const int inf = 0x3f3f3f3f;
const double dinf = 1e100;
typedef long long ll;
//const ll linf = 9223372036854775807LL;
// const ll linf = 1e18;
using namespace std;
const int maxn = 3e5 + 10;
int pre[maxn];
signed main()
{DDLC_ESCAPE_PLAN_FAILED;int t;cin >> t;while(t--){string s;cin >> s;int a = 0, b = 0;for(int i = 0; i < s.size(); ++i){if(i & 1) a = a * 10 + s[i] - '0';else b = b * 10 + s[i] - '0';}a++, b++;cout << a * b - 2 << endl;}return 0;
}
Codeforces Round #742 (Div. 2) 个人题解相关推荐
- Codeforces Round #742 (Div. 2) F. One-Four Overload 构造 + 二分图染色
传送门 文章目录 题意: 思路: 题意: 给你一个n∗mn*mn∗m的矩形,包含...和XXX,你有两种颜色,你需要给...染色使得每个XXX上下左右相邻的...其两种颜色个数相同,输出一种合法方案. ...
- Codeforces Round #686 (Div. 3) A-F题解
Codeforces Round #686 (Div. 3) A-F题解 A. Special Permutation 题意 给定 nnn ,输出一个长度为 nnn 的全排列,每个位置 iii 上的数 ...
- Codeforces Round #693 (Div. 3)部分题解
Codeforces Round #693 (Div. 3) 部分题解 D. Even-Odd Game 思路: 贪心:田忌赛马 (1)先将数组从大到小排序,取数时从大到小取,用一个ans变量记录取数 ...
- Codeforces Round #702 (Div. 3)A-G题解
Codeforces Round #702 (Div. 3)A-G题解 比赛链接:https://codeforces.ml/contest/1490 这场F读错题意白给一发,G二分的if(dp[mi ...
- codeforces Round #645 (Div. 2)D题解
Codeforces Round #645 (Div. 2)--D题解 作为一名菜鸡,理所当然得没有A出来,这道题数据放小就一水题了,可惜数据这块卡的死死的. 本题最重要的一点就是你要推出来一个结论: ...
- Codeforces Round #670 (Div. 2)A-D题解
Codeforces Round #670 (Div. 2)A-D题解 //写于rating值1987/2184 //补档 比赛链接:https://codeforces.ml/contest/140 ...
- Codeforces Round #674 (Div. 3)A-F题解
Codeforces Round #674 (Div. 3)A-F题解 比赛链接:https://codeforces.com/contest/1426 A题 水题不写题解 #include<b ...
- Codeforces Round #742 (Div. 2) B、C 题解
Codeforces Round 742 B. MEXor Mixup 题意 有一个数组,输入两个数a,b,a代表这个数组之外的最小非负整数,b代表这个数组的异或值,问你该数组的最小长度. 思路 首先 ...
- Codeforces Round #807 (Div. 2) A-C题解
Codeforces Round #807 (Div. 2) A.B.C题题解 A - Mark the Photographer 题意:马克要给2n个人照相,分两排,一排站n人,给出每个人的身高,要 ...
最新文章
- sqlanyshere转mysql_【SQL】Oracle和Mysql的分页、重复数据查询(limit、rownum、rowid)
- 大话设计模式之装饰模式
- 【源码分享】POSCMS功能如何实现短信验证码
- LeetCode 373. 查找和最小的K对数字(自定义优先队列BFS)
- 2017云栖大会:阿里巴巴宣布成立达摩院
- java有哪些类_Java中常用的类有哪些?
- SqlServer 日期时间格式 字符串相互转换 及相关函数
- 为什么Linux7没有tree命令,如何在Centos7中添加Tree命令
- matlab2018a怎么读取nc文件,[转]matlab批量读取nc文件
- Java Web前后端分离架构
- alc236黑苹果驱动_瑞昱 Realtek2.5G有线网卡 | RTL8125、RTL8156黑苹果驱动
- 【谷歌地图--PlacesSDK集成】
- Audio专业名词解析
- 四年,工作、辞职、学习
- html5多图合成gif,gif动态图片制作 多张图片合成gif动态图片
- 终端操作GitHub代码以及代码的版本控制(develop/master)多图
- HTML 画布入门(六)如何将图像添加到 HTML 画布
- 极速office(PPT)文字如何设置加粗
- Fatal error:Cannot ‘break‘ 2 levels in数据库导出错误解决
- SegmentFault 社区访谈 | 依云: 一只想依偎在云上的野百合