当前位置:网站首页>Codeforces Round #804 (Div. 2) Editorial(A-B)
Codeforces Round #804 (Div. 2) Editorial(A-B)
2022-07-06 05:11:00 【.Ashy.】
C的题解着实看不懂,先写写 A,B
A — The Third Three Number Problem
题意
给出一个数 n ,找出任意三个数 a b c 满足
( a ⊕ b ) + ( b ⊕ c ) + ( a ⊕ c ) = n (a⊕b)+(b⊕c)+(a⊕c)=n (a⊕b)+(b⊕c)+(a⊕c)=n
思路
首先根据
a + b = a ⊕ b + 2 ∗ ( a & b ) a+b=a⊕b+2*(a\&b) a+b=a⊕b+2∗(a&b)
这个式子可知
a ⊕ b a⊕b a⊕b 的奇偶性是与 a + b a+b a+b 相同的
故 ( a ⊕ b ) + ( b ⊕ c ) + ( a ⊕ c ) (a⊕b)+(b⊕c)+(a⊕c) (a⊕b)+(b⊕c)+(a⊕c)的奇偶性是与 ( a + b ) + ( b + c ) + ( a + c ) (a+b)+(b+c)+(a+c) (a+b)+(b+c)+(a+c) 相同的,是与 2 ∗ ( a + b + c ) 2*(a+b+c) 2∗(a+b+c) 的奇偶性相同 ,故 可证得 n 一定是个偶数 , 故在奇数情况下无解;
然后是构造,根据性质 a ⊕ 0 = a a⊕0=a a⊕0=a 我们 可以构造 0 0 n 2 n\over2 2n 三个数
#include<bits/stdc++.h>
using namespace std;
int n,t;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
if(n%2!=0) puts("-1");
else cout<<"0 0 "<<n/2<<endl;
}
}
B — Almost Ternary Matrix
题意
矩阵构造,使得每个块相连的块与其不同的恰好只有两个
思路:

把 n 与 m 取得稍大一点画出图既能看出规律
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a,b;
int t;
int s[51][51];
int main()
{
cin>>t;
while(t--)
{
cin>>a>>b;
s[1][1]=1;
s[1][2]=0;
s[2][1]=0;
s[2][2]=1;//先构造 2*2 的最小单位块
for(int i=3;i<=b;i++)
if(i%2==0) s[1][i]=s[1][i-3];
else s[1][i]=s[1][i-1];
for(int i=3;i<=b;i++)
if(i%2==0) s[2][i]=s[2][i-3];
else s[2][i]=s[2][i-1];//构造前两行
for(int i=3;i<=a;i++)
{
if(i%2==0)
{
for(int j=1;j<=b;j++)
{
s[i][j]=s[i-3][j];
}
}
else
{
for(int j=1;j<=b;j++)
{
s[i][j]=s[i-1][j];
}
}
}//构造后面行
for(int i=1;i<=a;i++)
{
for(int j=1;j<=b;j++)
{
cout<<s[i][j]<<" ";
}
puts("");
}
}//输出
return 0;
}
边栏推荐
- Leetcode 186 Flip the word II in the string (2022.07.05)
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Tetris
- RT thread analysis log system RT_ Kprintf analysis
- Three.js学习-光照和阴影(了解向)
- A little knowledge of CPU, disk and memory
- Supreme Court, judgment standard of divorce cases
- 内核判断i2c地址上是否挂载外设
- The web project imported the MySQL driver jar package but failed to load it into the driver
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
猜你喜欢
随机推荐
Oracle deletes duplicate data, leaving only one
Application of Flody
The video in win10 computer system does not display thumbnails
L'introduction en bourse de MSK Electronics a pris fin: 800 millions de RMB d'actifs de Henan étaient des actionnaires
TCP three handshakes you need to know
关于imx8mp的es8316的芯片调试
Weng Kai C language third week 3.1 punch in
yolov5 tensorrt加速
行业专网对比公网,优势在哪儿?能满足什么特定要求?
Ora-01779: the column corresponding to the non key value saving table cannot be modified
Sorting out the knowledge points of multicast and broadcasting
关于Unity Inspector上的一些常用技巧,一般用于编辑器扩展或者其他
2021 robocom world robot developer competition - undergraduate group (semi-finals)
Introduction of several RS485 isolated communication schemes
Orm-f & Q object
nacos-高可用seata之TC搭建(02)
F12 solve the problem that web pages cannot be copied
Postman关联
JS quick start (II)
2021RoboCom机器人开发者大赛(初赛)



![[数学建模] 微分方程--捕鱼业的持续发展](/img/7c/2ab6f2a34bc2c97318537ec8e0b0c5.png)
![[untitled]](/img/7e/d0724193f2f2c8681a68bda9e08289.jpg)


![[lgr-109] Luogu may race II & windy round 6](/img/fe/d5b67c7dff759c519a04da023630ea.png)
