当前位置:网站首页>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
边栏推荐
- All in all, the low code still needs to solve these four problems
- Note de développement du système embarqué 80: application du concepteur Qt à la conception de l'interface principale
- Hololens2 development environment building and deploying apps
- Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
- Maixll-Dock 使用方法
- Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
- 2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试
- 2022年聚合工艺考试题及模拟考试
- 如何看待智慧城市建设中的改变和机遇?
- Codeforces Round #721 (Div. 2)B1. Palindrome Game (easy version)B2. Palindrome game (hard version)
猜你喜欢

Coinbase in a bear market: losses, layoffs, stock price plunges

JS image path conversion Base64 format
![[recommended algorithm] C interview question of a small factory](/img/ae/9c83efe86c03763710ba5e4a2eea33.jpg)
[recommended algorithm] C interview question of a small factory

Question bank and answers for chemical automation control instrument operation certificate examination in 2022

Applications and features of VR online exhibition
![[deep learning] (4) decoder mechanism in transformer, complete pytoch code attached](/img/ec/96e3188902e399f536ebca79042af9.png)
[deep learning] (4) decoder mechanism in transformer, complete pytoch code attached

Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition

Do280 management application deployment --rc

NFT: utilisez EIP - 2981 pour commencer un voyage de redevances NFT

Dual contractual learning: text classification via label aware data augmentation reading notes
随机推荐
Announcement on the list of Guangdong famous high-tech products to be selected in 2021
网站服务器:好用的网站服务器怎么选这五方面要关注
JMeter learning notes 2 - brief introduction to graphical interface
Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
NFT: utilisez EIP - 2981 pour commencer un voyage de redevances NFT
Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
2022年化工自动化控制仪表操作证考试题库及答案
[today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET
Account sharing technology enables the farmers' market and reshapes the efficiency of transaction management services
[send email with error] 535 error:authentication failed
How to view the changes and opportunities in the construction of smart cities?
Grey correlation cases and codes
嵌入式系統開發筆記80:應用Qt Designer進行主界面設計
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.2 多属性注册协议(Multiple Registration Protocol (MRP))
Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]
Maixll-Dock 快速上手
Odeint et GPU
(12) Somersault cloud case (navigation bar highlights follow)
Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling
2022危险化学品生产单位安全生产管理人员题库及答案