当前位置:网站首页>Codeforces Round #804 (Div. 2)
Codeforces Round #804 (Div. 2)
2022-07-07 23:18:00 【AC自动寄】
目录
A. The Third Three Number Problem
官方题解
点击跳转:官方题解
A. The Third Three Number Problem
A. The Third Three Number Problem
思路:
首先,⊕(异或) 又称不进位加法,所以:对于 (a⊕b)+(b⊕c)+(a⊕c) 的最后的一位而言
(a⊕b)+(b⊕c)+(a⊕c) = a + b + b + c + a + c = 2*(a + b + c) 必为偶数
故:当 n 为奇数时,无解
当 n 为偶数时:
知:a⊕0 = a ,所以,令 a = 0, b = n / 2, c = n / 2;
此时:a⊕b = n/2,a⊕c = n/2,b⊕c = 0,结果为 n 成立
代码如下:
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 2e5 + 10, mod = 1e9 + 7;
int T;
int lowbit(int x)
{
return x & -x;
}
void solve()
{
int n, c;
scanf("%d", &n);
if(n%2)
{
puts("-1");
return ;
}
printf("%d %d %d\n", 0, n/2, n/2);
//printf("%d\n", res);
}
int main()
{
//fast;
//cin >> T;
scanf("%d", &T);
while(T -- )
solve();
return 0;
}
B. Almost Ternary Matrix
思路:
类似:
10011001
01100110
01100110
10011001
模拟构造即可
代码如下:
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 110, mod = 1e9 + 7;
int T;
int lowbit(int x)
{
return x & -x;
}
void solve()
{
int n, m;
scanf("%d %d", &n, &m);
string r1, r2;
while(true)
{
if(r1.size() < 2 * m) r1 += "1 0 ";
else break;
if(r1.size() < 2 * m) r1 += "0 1 ";
else break;
}
while(true)
{
if(r2.size() < 2 * m) r2 += "0 1 ";
else break;
if(r2.size() < 2 * m) r2 += "1 0 ";
else break;
}
int a[N][N];
for(int i = 1; i <= n; i ++ )
{
if(i % 4 == 1 || i % 4 == 0) cout << r1 << endl;
else cout << r2 << endl;
}
//printf("%d\n", res);
}
int main()
{
//fast;
//cin >> T;
scanf("%d", &T);
while(T -- )
solve();
return 0;
}
此段代码也有类似效果:
void solve()
{
int n, m;
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i ++ )
{
for(int j = 1; j <= m; j ++ )
cout << ((i % 4 <= 1)==(j % 4 <= 1)) << " ";
puts("");
}
//printf("%d\n", res);
}
C. The Third Problem
思路:
res = 每个数能变换的范围
分析:
01的位置不能变;
对于其余的数,小于本数的数在本数的一侧,则本数也不能动;
其余的数能动,能动的范围为比本数小的数组成的区间;
代码如下:
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10, mod = 1e9 + 7;
int T;
void solve()
{
int n, m;
scanf("%d", &n);
int a[N] = {0}, p[N] = {0};
for(int i = 0; i < n; i ++ )
{
scanf("%d", &a[i]);
p[a[i]] = i;
}
int res = 1;
int l = p[0], r = p[0];
for(int i = 1; i < n; i ++ )
{
if(p[i] < l) l = p[i];
else if(p[i] > r) r = p[i];
else res = (LL)res*(r - l + 1 - i) % mod;
//cout << res << endl;
}
printf("%d\n", res);
//printf("%d\n", res);
}
int main()
{
//fast;
//cin >> T;
scanf("%d", &T);
while(T -- )
solve();
return 0;
}
边栏推荐
- New library online | cnopendata China Star Hotel data
- 8道经典C语言指针笔试题解析
- 《因果性Causality》教程,哥本哈根大学Jonas Peters讲授
- SDNU_ACM_ICPC_2022_Summer_Practice(1~2)
- [Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output
- 10.CNN应用于手写数字识别
- Interface test advanced interface script use - apipost (pre / post execution script)
- Reentrantlock fair lock source code Chapter 0
- 接口测试要测试什么?
- They gathered at the 2022 ecug con just for "China's technological power"
猜你喜欢
Reptile practice (VIII): reptile expression pack
[Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output
基于微信小程序开发的我最在行的小游戏
Letcode43: string multiplication
Kubernetes static pod (static POD)
Jemter distributed
Prediction of the victory or defeat of the League of heroes -- simple KFC Colonel
SDNU_ACM_ICPC_2022_Summer_Practice(1~2)
完整的模型验证(测试,demo)套路
51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up
随机推荐
7.正则化应用
Basic types of 100 questions for basic grammar of Niuke
赞!idea 如何单窗口打开多个项目?
【obs】官方是配置USE_GPU_PRIORITY 效果为TRUE的
tourist的NTT模板
Reentrantlock fair lock source code Chapter 0
Service Mesh的基本模式
From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
Introduction to paddle - using lenet to realize image classification method II in MNIST
What is load balancing? How does DNS achieve load balancing?
基于微信小程序开发的我最在行的小游戏
国内首次,3位清华姚班本科生斩获STOC最佳学生论文奖
SDNU_ ACM_ ICPC_ 2022_ Summer_ Practice(1~2)
Malware detection method based on convolutional neural network
牛客基础语法必刷100题之基本类型
AI遮天传 ML-初识决策树
NVIDIA Jetson测试安装yolox过程记录
C#中string用法
5g NR system messages
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)