当前位置:网站首页>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;
}
边栏推荐
- Zynq learning notes (3) - partial reconfiguration
- GAMES202-WebGL中shader的编译和连接(了解向)
- 麥斯克電子IPO被終止:曾擬募資8億 河南資產是股東
- Easy to understand I2C protocol
- Steady, 35K, byte business data analysis post
- Quelques conseils communs sur l'inspecteur de l'unit é, généralement pour les extensions d'éditeur ou d'autres
- 树莓派3.5寸屏幕白屏显示连接
- Microblogging hot search stock selection strategy
- On the solution of es8316's audio burst
- Oracle query table index, unique constraint, field
猜你喜欢
Postman pre script - global variables and environment variables
Ora-01779: the column corresponding to the non key value saving table cannot be modified
[effective Objective-C] - memory management
nacos-高可用seata之TC搭建(02)
Rce code and Command Execution Vulnerability
SQL injection vulnerability (MSSQL injection)
Flink kakfa data read and write to Hudi
[数学建模] 微分方程--捕鱼业的持续发展
RT thread analysis - object container implementation and function
Summary of redis basic knowledge points
随机推荐
Yolov5 tensorrt acceleration
Biscuits (examination version)
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
MySQL if and ifnull use
趋势前沿 | 达摩院语音 AI 最新技术大全
Postman前置脚本-全局变量和环境变量
Principle and performance analysis of lepton lossless compression
RT thread analysis log system RT_ Kprintf analysis
Request (request object) and response (response object)
ORM aggregate query and native database operation
Vite configures the development environment and production environment
ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
Review of double pointer problems
Nacos TC setup of highly available Seata (02)
Acwing week 58
【LeetCode】18、四数之和
Oracle query table index, unique constraint, field
Three methods of Oracle two table Association update
内核判断i2c地址上是否挂载外设