当前位置:网站首页>Codeforces Round #771 (Div. 2) ABCD|E
Codeforces Round #771 (Div. 2) ABCD|E
2022-07-01 04:36:00 【HeartFireY】
A.Reverse
Ideas
Give a [ 1 , n ] [1, n] [1,n] Permutation , It is required to flip the interval once , Minimize dictionary order . The dictionary order of one operation is the smallest , Then the sequence length from the beginning after the operation should be + 1 +1 +1.
So it is obviously to find the first misplaced position , The current point number of this position must be greater than its coordinates ( Prove slightly ). Then find the number position that should be placed on this position , Just reverse the interval , This ensures that the sequence is incremented by a number , Minimize dictionary order .
Accepted Code
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 600;
int a[N];
inline void solve(){
int n = 0; cin >> n;
int minpos = 0, maxpos = 0, minn = 10000000, maxx = 0;
for(int i = 1; i <= n; i++) cin >> a[i];
int l = 0, r = 0;
for(int i = 1; i <= n; i++){
if(!l){
if(a[i] != i) l = i; }
else{
if(a[i] == l) r = i; }
}
reverse(a + l, a + r + 1);
for(int i = 1; i <= n; i++) cout << a[i] << ' ';
cout << endl;
}
signed main(){
int t = 0; cin >> t;
while(t--) solve();
return 0;
}
B.Odd Swap Sort
Ideas
Adding to an odd number allows exchange , So let's discuss it by parity , If there are inverse pairs in odd and even sequences , Then it must not be successful ( Unable to swap locations ).
Accepted Code
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define yes puts("YES")
#define no puts("NO")
const int N = 100005;
int a[N];
inline void solve(){
int n = 0; cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
int book1 = 0, book2 = 0;
for(int i = 1; i <= n; i++){
if(a[i] & 1){
if(a[i] < book1){
no; return; }
book1 = a[i];
}
else{
if(a[i] < book2){
no; return; }
book2 = a[i];
}
}
yes;
}
signed main(){
int t = 0; cin >> t;
while(t--) solve();
return 0;
}
C.Inversion Graph
Ideas
The connection between pairs in reverse order , Check the number of connected blocks .
You can do this by maintaining the monotone stack . But there are better ways to write :
For two connected blocks , The merging condition is that there is at least one reverse order pair in two connected blocks , That is to say, the large node in front will contain the small node in the back . So we just need to sort the entire sequence , Then find the largest i d id id The number of homing times is enough .
Accepted Code
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10;
struct node{
int id, val;
const bool operator< (const node &aa){
return val < aa.val; }
}a[N];
//int a[N];
inline void solve(){
int n = 0; cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i].val, a[i].id = i;
sort(a + 1, a + 1 + n);
int maxx = 0, cnt = 0;
for(int i = 1; i <= n; i++){
maxx = max(maxx, a[i].id);
if(maxx == i) cnt++, maxx = a[i + 1].id;
}
cout << cnt << endl;
}
signed main(){
int t = 0; cin >> t;
while(t--) solve();
return 0;
}
D.Big Brush
Ideas
The title requires the steps of vat dyeing ... It looks like a simulation .
First, traverse the whole graph , Find the starting point , Then start from the starting point and delete backwards , Get the operation sequence and then output it backwards , It's operation. .
The deletion process can BFS perhaps DFS( Not written ).
Accepted Code
#include <bits/stdc++.h>
#define endl "\n"
const int dxy[] = {
0, 1}, N = 1010;
int g[N][N];
inline void solve(){
int n, m, cnt = 0; std::cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++) std::cin >> g[i][j];
auto check = [&](int x, int y, int res = 0){
if(x >=n || x < 1 || y >= m || y < 1) return 0;
for(auto i : dxy) for(auto j : dxy){
if(g[x + i][y + j]) res = g[x + i][y + j];
}
for(auto i : dxy) for(auto j : dxy){
if(g[x + i][y + j] && g[x + i][y + j] != res) return 0;
}
return res;
};
auto reset = [&](int x, int y){
for(auto i : dxy) for(auto j : dxy) g[x + i][y + j] = 0;
};
struct node {
int x, y, c; };
std::stack<node> ans;
std::queue<node> q;
for(int i = 1; i < n; i++){
for(int j = 1; j < m; j++){
int res = check(i, j);
if(res){
q.emplace(node{
i, j, res}); break; }
}
}
while(q.size()){
node now = q.front(); q.pop();
if(check(now.x, now.y) == now.c){
ans.emplace(now);
reset(now.x, now.y);
for(int i = -1; i <= 1; i++){
for(int j = -1; j <= 1; j++){
int nx = now.x + i, ny = now.y + j, res = check(nx, ny);
if(res) q.emplace(node{
nx, ny, res});
}
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(g[i][j]){
puts("-1"); return; }
}
}
std::cout << ans.size() << endl;
while(ans.size()){
auto now = ans.top(); ans.pop();
std::cout << now.x << ' ' << now.y << ' ' << now.c << endl;
}
}
signed main(){
std::ios_base::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
solve();
return 0;
}
E.Colorful Operations
Kodori tree + Differential tree array , See blog for details : CF1638E. Colorful Operations Kodori tree + Differential tree array _HeartFireY The blog of -CSDN Blog
边栏推荐
- JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction
- 2022 gas examination question bank and online simulation examination
- PgSQL failed to start after installation
- js 图片路径转换base64格式
- How to do the performance pressure test of "Health Code"
- Ten wastes of software research and development: the other side of research and development efficiency
- Embedded System Development Notes 80: using QT designer to design the main interface
- Why is Hong Kong server most suitable for overseas website construction
- [human version] Web3 privacy game in the dark forest
- Web server: how to choose a good web server these five aspects should be paid attention to
猜你喜欢

Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling

JMeter learning notes 2 - brief introduction to graphical interface

【深度学习】(4) Transformer 中的 Decoder 机制,附Pytorch完整代码

Grey correlation cases and codes

slf4j 简单实现

Custom components in applets

Mallbook: how can hotel enterprises break the situation in the post epidemic era?

2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers

Chen Yu (Aqua) - Safety - & gt; Cloud Security - & gt; Multicloud security

MySQL advanced -- you will have a new understanding of MySQL
随机推荐
In the innovation community, the "100 cities Tour" of the gold warehouse of the National People's Congress of 2022 was launched
Use winmtr software to simply analyze, track and detect network routing
Task04 mathematical statistics
【LeetCode】100. Same tree
嵌入式系统开发笔记81:使用Dialog组件设计提示对话框
25.k sets of flipped linked lists
Custom components in applets
"Target detection" + "visual understanding" realizes the understanding of the input image
Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记
Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]
Spock单元测试框架介绍及在美团优选的实践___第一章
PgSQL failed to start after installation
2022 gas examination question bank and online simulation examination
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
It's settled! 2022 JD cloud summit of JD global technology Explorer conference see you in Beijing on July 13
【发送邮件报错】535 Error:authentication failed
slf4j 简单实现
[today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET
Software testing needs more and more talents. Why do you still not want to take this path?
扩展-Fragment