当前位置:网站首页>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;
}
边栏推荐
- 【OSPF 和 ISIS 在多路访问网络中对掩码的要求】
- Mongodb basic knowledge summary
- Simple understanding of interpreters and compilers
- Flody的应用
- Nacos TC setup of highly available Seata (02)
- Flink kakfa data read and write to Hudi
- [effective Objective-C] - memory management
- The web project imported the MySQL driver jar package but failed to load it into the driver
- The kernel determines whether peripherals are attached to the I2C address
- 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
猜你喜欢

RT thread analysis - object container implementation and function

你需要知道的 TCP 三次握手

Introduction of several RS485 isolated communication schemes

Fiddler installed the certificate, or prompted that the certificate is invalid

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

acwing周赛58

Pagoda configuration mongodb

GAMES202-WebGL中shader的編譯和連接(了解向)

RTP gb28181 document testing tool
![[mathematical modeling] differential equation -- sustainable development of fishing industry](/img/7c/2ab6f2a34bc2c97318537ec8e0b0c5.png)
[mathematical modeling] differential equation -- sustainable development of fishing industry
随机推荐
Quelques conseils communs sur l'inspecteur de l'unit é, généralement pour les extensions d'éditeur ou d'autres
CUDA11.1在线安装
Microblogging hot search stock selection strategy
Modbus协议通信异常
集合详解之 Map + 面试题
Crazy God said redis notes
Three methods of Oracle two table Association update
A little knowledge of CPU, disk and memory
Hometown 20 years later (primary school exercises)
[buuctf.reverse] 159_[watevrCTF 2019]Watshell
What are the advantages of the industry private network over the public network? What specific requirements can be met?
Ad20 is set with through-hole direct connection copper sheet, and the bonding pad is cross connected
GAMES202-WebGL中shader的編譯和連接(了解向)
MySQL time processing
In 2022, we must enter the big factory as soon as possible
Simple understanding of interpreters and compilers
Lepton 无损压缩原理及性能分析
[noip2009 popularization group] score line delimitation
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
Flink kakfa data read and write to Hudi