当前位置:网站首页>Codeforces Round #804 (Div. 2) - A, B, C
Codeforces Round #804 (Div. 2) - A, B, C
2022-07-05 20:23:00 【Dimple】
https://codeforces.com/contest/1699
C. The Third Problem
The question
Given a 0 0 0 To n − 1 n-1 n−1 The whole arrangement , Ask how many 0 0 0 To n − 1 n-1 n−1 The full arrangement of is similar to this arrangement ?
The answer is right 1e9+7 modulus .
Similarity definition : If two full permutations meet the following conditions , Let's say that the two are similar in full arrangement .
- For any interval [ l , r ] ( 1 ≤ l ≤ r ≤ n ) [l, r] (1 \le l \le r \le n) [l,r](1≤l≤r≤n) All satisfied with : MEX ( [ a l , a l + 1 , … , a r ] ) = MEX ( [ b l , b l + 1 , … , b r ] ) \operatorname{MEX}([a_l,a_{l+1},\ldots,a_r])=\operatorname{MEX}([b_l,b_{l+1},\ldots,b_r]) MEX([al,al+1,…,ar])=MEX([bl,bl+1,…,br])
For a pile of numbers c 1 , c 2 , … , c k c_1,c_2,\ldots,c_k c1,c2,…,ck Of MEX \operatorname{MEX} MEX Refer to , In collection c c c The first non negative integer that does not appear in x x x.
Ideas
from 0 To n-1, Count one by one , See where it can be placed . Multiplication of all possible positions is the answer .
Number of tags x
The position in the original arrangement is p[x]
.
- First, it's easy to determine ,0 and 1 The position in a similar arrangement does not change , All for
p[0]
. set upl
Is the left end position ,r
Is the right end position . - about 2:
1. Ifp[2]
be located[l, r]
in , that 2 Can be placed in[l, r]
All free locations in ;
(2 Originally in[l, r]
in , that MEX [ l , r ] \operatorname{MEX}[l, r] MEX[l,r] To achieve 3 了 , So in a similar arrangement 2 Only on the[l, r]
in )
2. otherwise ,2 It can only be placed in its original positionp[2]
; thenp[2]
takel
perhapsr
to update ;
(2 Originally in[l, r]
outside , that MEX [ l , r ] \operatorname{MEX}[l, r] MEX[l,r] It can only reach 2,2 Can't be in[l, r]
in ; And if its position changes , There will be intervals MEX Value change , So in this case 2 The position of the cannot be changed ) - about 3:
1. Ifp[3]
be located[l, r]
in , that 3 Can be placed in[l, r]
All free locations in ;
2. otherwise ,3 It can only be placed in its original positionp[3]
; thenp[3]
takel
perhapsr
to update ; - …
Code
#include<bits/stdc++.h>
using namespace std;
#define Ios ios::sync_with_stdio(false),cin.tie(0)
const int N = 200010, mod = 1e9+7;
int T, n, m;
int a[N], p[N];
signed main(){
Ios;
cin >> T;
while(T--)
{
cin >> n;
for(int i=1;i<=n;i++) cin >> a[i], p[a[i]] = i;
int ans = 1;
int l = min(p[0], p[1]), r = max(p[0], p[1]);
for(int i=2;i<n;i++)
{
if(p[i] > l && p[i] < r)
{
ans = ans * (r-l+1 - i) % mod;
}
else{
if(p[i] < l) l = p[i];
else r = p[i];
}
}
cout << ans << endl;
}
return 0;
}
Experience
When there is no idea, you should calm down and push back bit by bit from the initial situation , Maybe there is a way to push .
Instead of looking at the sample and thinking ..
B. Almost Ternary Matrix
The question
Construct a n*m Of 01 matrix , bring :
- For each location , In its directly adjacent position , There are exactly two locations that are different from this location element .
2 ≤ n , m ≤ 50 2 \le n,m \le 50 2≤n,m≤50 And all are even .
Ideas
So constructed :
6 8
1 0 0 1 1 0 0 1
0 1 1 0 0 1 1 0
0 1 1 0 0 1 1 0
1 0 0 1 1 0 0 1
1 0 0 1 1 0 0 1
0 1 1 0 0 1 1 0
Code
#include<bits/stdc++.h>
using namespace std;
const int N = 210, mod = 1e9+7;
int T, n, m;
int a[N] = {
1, 0, 0, 1}, b[N] = {
0, 1, 1, 0};
int ans[N][N];
signed main(){
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &m);
for(int i=1;i<=n;i++)
{
for(int j=0;j<m;j++)
{
if(i%4 == 1 || i%4 == 0) ans[i][j] = a[j%4];
else ans[i][j] = b[j%4];
}
}
for(int i=1;i<=n;i++){
for(int j=0;j<m;j++){
printf("%d ", ans[i][j]);
}
printf("\n");
}
}
return 0;
}
A. The Third Three Number Problem
The question
Give a number n n n, Find three numbers a , b , c a, b, c a,b,c Satisfy :
- ( a ⊕ b ) + ( b ⊕ c ) + ( a ⊕ c ) = n (a\oplus b)+(b\oplus c)+(a\oplus c)=n (a⊕b)+(b⊕c)+(a⊕c)=n
Output not found − 1 -1 −1.
1 ≤ n ≤ 1 0 9 , 0 ≤ a , b , c ≤ 1 0 9 1 \le n \le 10^9,\ 0 \le a, b, c \le 10^9 1≤n≤109, 0≤a,b,c≤109
Ideas
from a + b = a ⊕ b + 2 ⋅ ( a a + b = a \oplus b + 2 \cdot (a a+b=a⊕b+2⋅(a & b ) b) b) You know , a ⊕ b a \oplus b a⊕b and a + b a + b a+b Having the same parity .
that n = ( a ⊕ b ) + ( b ⊕ c ) + ( a ⊕ c ) n = (a\oplus b)+(b\oplus c)+(a\oplus c) n=(a⊕b)+(b⊕c)+(a⊕c) Just like ( a + b ) + ( b + c ) + ( a + c ) = 2 ⋅ ( a + b + c ) (a+b) + (b+c) + (a+c) =2 \cdot (a+b+c) (a+b)+(b+c)+(a+c)=2⋅(a+b+c) Having the same parity , It must be an even number .
- When n by Odd number output -1.
- otherwise Make b = c = 0 b=c=0 b=c=0, Then the original formula becomes : a + a = n a + a = n a+a=n, that a = n 2 a = \frac n 2 a=2n.
Code
#include<bits/stdc++.h>
using namespace std;
#define Ios ios::sync_with_stdio(false),cin.tie(0)
const int N = 200010, mod = 1e9+7;
int T, n, m;
int a[N];
signed main(){
Ios;
cin >> T;
while(T--)
{
cin >> n;
if(n % 2 == 0) cout << n/2 << " " << 0 << " " << 0 << endl;
else cout << -1 << endl;
}
return 0;
}
Experience
Focus on special circumstances .
边栏推荐
- 信息学奥赛一本通 1337:【例3-2】单词查找树 | 洛谷 P5755 [NOI2000] 单词查找树
- Practical demonstration: how can the production research team efficiently build the requirements workflow?
- Unity编辑器扩展 UI控件篇
- 港股将迎“最牛十元店“,名创优品能借IPO突围?
- ICTCLAS word Lucene 4.9 binding
- Codeforces Round #804 (Div. 2) - A, B, C
- [quick start of Digital IC Verification] 7. Basic knowledge of digital circuits necessary for verification positions (including common interview questions)
- c語言oj得pe,ACM入門之OJ~
- kubernetes资源对象介绍及常用命令(五)-(ConfigMap&Secret)
- nprogress插件 进度条
猜你喜欢
Leetcode skimming: binary tree 17 (construct binary tree from middle order and post order traversal sequence)
PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
小程序页面导航
【数字IC验证快速入门】1、浅谈数字IC验证,了解专栏内容,明确学习目标
Solve the problem that the database configuration information under the ThinkPHP framework application directory is still connected by default after modification
Informatics Orsay all in one 1339: [example 3-4] find the post order traversal | Valley p1827 [usaco3.4] American Heritage
618 "low key" curtain call, how can baiqiushangmei join hands with the brand to cross the "uncertain era"?
信息学奥赛一本通 1339:【例3-4】求后序遍历 | 洛谷 P1827 [USACO3.4] 美国血统 American Heritage
实操演示:产研团队如何高效构建需求工作流?
- Oui. Net Distributed Transaction and Landing Solution
随机推荐
sort和投影
B站UP搭建世界首个纯红石神经网络、基于深度学习动作识别的色情检测、陈天奇《机器学编译MLC》课程进展、AI前沿论文 | ShowMeAI资讯日报 #07.05
When JS method passes long type ID value, precision loss will occur
How to choose a good external disk platform, safe and formal?
零道云新UI设计中
Minimum commission for stock trading account opening, where to open an account with low commission? Is it safe to open an account on your mobile phone
Leetcode brush question: binary tree 14 (sum of left leaves)
插值查找的简单理解
Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)
【数字IC验证快速入门】2、通过一个SoC项目实例,了解SoC的架构,初探数字系统设计流程
y57.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(三十)
小程序全局配置
Leetcode(347)——前 K 个高频元素
mongodb/文档操作
2020 CCPC 威海 - A. Golden Spirit(思维),D. ABC Conjecture(大数分解 / 思维)
model方法
Informatics Olympiad 1340: [example 3-5] extended binary tree
基金网上开户安全吗?去哪里开,可以拿到低佣金?
ROS2专题【01】:win10上安装ROS2
1. Strengthen learning basic knowledge points