当前位置:网站首页>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 uplIs the left end position ,rIs 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]takelperhapsrto 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]takelperhapsrto 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 .
边栏推荐
- 鸿蒙os第四次学习
- 【数字IC验证快速入门】8、数字IC中的典型电路及其对应的Verilog描述方法
- 2020 CCPC 威海 - A. Golden Spirit(思维),D. ABC Conjecture(大数分解 / 思维)
- When JS method passes long type ID value, precision loss will occur
- CVPR 2022 | 常见3D损坏和数据增强
- Rainbond 5.7.1 支持对接多家公有云和集群异常报警
- y57.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(三十)
- Summer Challenge harmonyos - realize message notification function
- Schema and model
- Go language learning tutorial (XV)
猜你喜欢

Scala基础【HelloWorld代码解析,变量和标识符】

IC科普文:ECO的那些事儿
![[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives](/img/90/88a1f79a07016738d2688548e21949.png)
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives

618 "low key" curtain call, how can baiqiushangmei join hands with the brand to cross the "uncertain era"?

【数字IC验证快速入门】3、数字IC设计全流程介绍

CVPR 2022 | 常见3D损坏和数据增强

Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)

.Net分布式事务及落地解决方案

欢迎来战,赢取丰厚奖金:Code Golf 代码高尔夫挑战赛正式启动

死信队列入门(两个消费者,一个生产者)
随机推荐
【数字IC验证快速入门】6、Questasim 快速上手使用(以全加器设计与验证为例)
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives
.Net分布式事务及落地解决方案
港股将迎“最牛十元店“,名创优品能借IPO突围?
2022北京眼睛健康用品展,护眼产品展,中国眼博会11月举办
leetcode刷题:二叉树14(左叶子之和)
Go language | 01 wsl+vscode environment construction pit avoidance Guide
Relationship between mongodb documents
基金网上开户安全吗?去哪里开,可以拿到低佣金?
【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
DP: tree DP
[quick start of Digital IC Verification] 9. Finite state machine (FSM) necessary for Verilog RTL design
y57.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(三十)
DP:树DP
计算lnx的一种方式
When JS method passes long type ID value, precision loss will occur
Elk distributed log analysis system deployment (Huawei cloud)
A solution to PHP's inability to convert strings into JSON
Leetcode skimming: binary tree 17 (construct binary tree from middle order and post order traversal sequence)
MySql的root密码忘记该怎么找回