当前位置:网站首页>(codeforce1699) a & B (construction)
(codeforce1699) a & B (construction)
2022-07-18 08:52:00 【AC__ dream】
A. The Third Three Number Problem
Topic link :Problem - A - Codeforces
The sample input :
5
4
1
12
2046
194723326
Sample output :
3 3 1
-1
2 4 6
69 420 666
12345678 87654321 100000000
The question : Multiple sets of samples , One sample per group n, Ask if we can find three numbers that satisfy the equation
(a⊕b)+(b⊕c)+(a⊕c)=n(a⊕b)+(b⊕c)+(a⊕c)=n, If you can find it, output a,b,c, Otherwise output -1
analysis :
Let's first look at what kind of n It must not be found a,b,c Satisfied with the question
First of all, there is :
Odd numbers and odd numbers are XOR to get an even number
An even number is obtained by exclusive or of an even number
An odd number that is exclusive or of odd and even numbers
So when a,b,c When all three numbers are odd or even ,n It must be an even number
When a,b,c When two of the three numbers are odd , Might as well set a,b Is odd , Then there are n For me + p. + p. = accidentally
When a,b,c When two of the three numbers are even , Might as well set a,b It's even , Then there are n For me + p. + p. = accidentally
So no matter a,b,c It is impossible to get an odd number by taking any value , So when n When it is an odd number, it must be -1
When n For even when , We can make a=b=n>>1,c=0, This is a set of solutions that meet the meaning of the problem
Here's the code :
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int N=1e5+10;
int main()
{
int T;
cin>>T;
while(T--)
{
long long n;
scanf("%lld",&n);
if(n&1) puts("-1");
else
printf("%lld %lld 0\n",n>>1,n>>1);
}
return 0;
} B. Almost Ternary Matrix
Topic link :Problem - B - Codeforces

The sample input :
3
2 4
2 2
4 4
Sample output :
1 0 0 1
0 1 1 0
1 0
0 1
1 0 1 0
0 0 1 1
1 1 0 0
0 1 0 1
The question : Multi group input , One sample per group n,m(n and m Is an even number ) Represents that we need to construct a n*m Matrix , Every number in the matrix is 0 perhaps 1, Meet each 0 There is 2 individual 1, Every 1 There is 2 individual 0, The surrounding of each grid refers to the four adjacent grids up, down, left and right .
analysis : We can directly simulate the structure , I follow the example 1 Constructed in that way , namely :
When i In an odd number of , We put i*2-1 Row sum i*2 Rows are constructed as follows
0 1 1 0 0 1 1 0……
1 0 0 1 1 0 0 1……
When i For even when , We put i*2-1 Row sum i*2 Rows are constructed as follows
1 0 0 1 1 0 0 1……
0 1 1 0 0 1 1 0……
i from 1 Traversing n/2 that will do .
Here is the code :
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int N=1e2+10;
int s[N][N];
int main()
{
int T;
cin>>T;
while(T--)
{
int n,m,t;
scanf("%d%d",&n,&m);
for(int i=1;i*2<=n;i++)
{
if(i&1) t=1;
else t=0;
for(int j=1;j*2<=m;j++)
{
if((j+t)&1)
{
s[i*2-1][j*2-1]='0';
s[i*2-1][j*2]='1';
s[i*2][j*2-1]='1';
s[i*2][j*2]='0';
}
else
{
s[i*2-1][j*2-1]='1';
s[i*2-1][j*2]='0';
s[i*2][j*2-1]='0';
s[i*2][j*2]='1';
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
printf("%c ",s[i][j]);
puts("");
}
}
return 0;
}边栏推荐
- 【Luogu_P4820】 【国家集训队】书堆【数学】【物理】【调和级数】
- SAP s/4hana new simplified data model (NSDM) model introduction
- 电子招标采购商城系统:优化传统采购业务,提速企业数字化升级
- 同花顺开户安全吗,同属顺是证券公司吗?
- 【无标题】
- Logic of archives | holonomic distinction and examples
- Honghu Wanlian Zhiyuan development board is officially integrated into the openharmony backbone
- Several common methods of database table query in SAP ABAP system
- 健康防猝指南1:体重和减肥的秘密
- 达芬奇pro的FPGA学习笔记6.2--vcs和verdi开发蜂鸟e203
猜你喜欢

如何清理你的电子邮件订阅者名单以改善电子邮件营销

90% of people have never used Microsoft!

无需训练代码,推理性能提升1.4~7.1倍,业界首个自动模型压缩工具开源

关于MySQL的基础学习

When the wechat applet activates the account, it will prompt "this account has been activated, please log in directly with the account password"

Modifying background photos and using skills of idea

好的架构是进化来的,不是设计来的

使电脑拥有公网IP方法

MySQL about the installation process of zip installation package
![[leetcode binary tree -- maximum path sum] 124 Maximum path sum in binary tree](/img/35/20fc28f42fc3116c4f644d117de4f3.png)
[leetcode binary tree -- maximum path sum] 124 Maximum path sum in binary tree
随机推荐
[2023 school recruitment questions] column planning (non final presentation status, for bloggers' personal reference)
【集训DAY3】 Reconstruction of roads【SPFA】
[深入研究4G/5G/6G专题-37]: URLLC-8-《3GPP URLLC相关协议、规范、技术原理深度解读》-2-网络架构、时延分析与URLLC载波部署形态
Opencv tutorial 01: introduction and installation, basic operations of pictures and videos
在线SQL转YAML工具
九联科技开发板正式合入OpenHarmony主干
uniapp自定义头部组件
docker mysql容器如何开启慢查询日志
290页11万字数字农业农村项目规划建设方案2022
DNS攻击防护原理
类加载器&双亲委派机制&打破双亲委派机制
SQL杂谈
MySQL中KEY、PRIMARY KEY、UNIQUE KEY、INDEX 的区别
How to set the allure test report
IDEA的修改背景照片and使用技巧
有哪些值得学习的 Go 语言开源项目
The logic of archives | archives collection
In the throes of household appliance market transformation, SaaS system platform is applied to inject new momentum into the development of household appliance industry
Top ten cases of "enterprise digital transformation"!
木马病毒清除方式