当前位置:网站首页>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 .
边栏推荐
- Leetcode(695)——岛屿的最大面积
- 什么是pyc文件
- A way to calculate LNX
- CTF逆向基础
- Leetcode brush questions: binary tree 11 (balanced binary tree)
- E. Singhal and Numbers(质因数分解)
- 【数字IC验证快速入门】2、通过一个SoC项目实例,了解SoC的架构,初探数字系统设计流程
- 2020 CCPC 威海 - A. Golden Spirit(思维),D. ABC Conjecture(大数分解 / 思维)
- Leetcode (347) - top k high frequency elements
- Rainbond 5.7.1 支持对接多家公有云和集群异常报警
猜你喜欢
[quick start of Digital IC Verification] 7. Basic knowledge of digital circuits necessary for verification positions (including common interview questions)
Informatics Orsay all in one 1339: [example 3-4] find the post order traversal | Valley p1827 [usaco3.4] American Heritage
基础篇——配置文件解析
Elk distributed log analysis system deployment (Huawei cloud)
【数字IC验证快速入门】1、浅谈数字IC验证,了解专栏内容,明确学习目标
.Net分布式事務及落地解决方案
Enter the parallel world
kubernetes资源对象介绍及常用命令(五)-(ConfigMap&Secret)
leetcode刷题:二叉树14(左叶子之和)
Zero cloud new UI design
随机推荐
Enter the parallel world
如何形成规范的接口文档
本季度干货导航 | 2022年Q2
Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)
mongodb/文档操作
Solve the problem that the database configuration information under the ThinkPHP framework application directory is still connected by default after modification
19 Mongoose模块化
When JS method passes long type ID value, precision loss will occur
July 4, 2022 - July 10, 2022 (UE4 video tutorial MySQL)
A solution to PHP's inability to convert strings into JSON
Is it safe for CICC fortune to open an account online?
[quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design
计算lnx的一种方式
港股将迎“最牛十元店“,名创优品能借IPO突围?
CTF逆向基础
sort和投影
How to retrieve the root password of MySQL if you forget it
Wechat applet regular expression extraction link
【c语言】归并排序
【愚公系列】2022年7月 Go教学课程 004-Go代码注释