当前位置:网站首页>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
边栏推荐
- Programs and processes, process management, foreground and background processes
- Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
- Embedded System Development Notes 80: using QT designer to design the main interface
- Coinbase in a bear market: losses, layoffs, stock price plunges
- 做网站数据采集,怎么选择合适的服务器呢?
- MySQL winter vacation self-study 2022 12 (5)
- Common thread methods and daemon threads
- Note de développement du système embarqué 80: application du concepteur Qt à la conception de l'interface principale
- Applications and features of VR online exhibition
- Possible problems and solutions of using scroll view to implement slider view
猜你喜欢

OdeInt与GPU

Obtain detailed ideas for ABCDEF questions of 2022 American Games

Maixll-Dock 使用方法

嵌入式系统开发笔记79:为什么要获取本机网卡IP地址

JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction

Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling

【LeetCode】100. Same tree

Task04 | statistiques mathématiques

Procurement intelligence is about to break out, and Alipay'3+2'system helps enterprises build core competitive advantages

Recommend the best product development process in the Internet industry!
随机推荐
Simple implementation of slf4j
跳槽一次涨8k,5年跳了3次...
什么是uid?什么是Auth?什么是验证器?
【发送邮件报错】535 Error:authentication failed
PgSQL failed to start after installation
Valid @suppresswarnings warning name
[ue4] event distribution mechanism of reflective event distributor and active call event mechanism
OSPF notes [multiple access, two multicast addresses with OSPF]
Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]
[learn C and fly] S1E20: two dimensional array
Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记
Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
The index is invalid
Procurement intelligence is about to break out, and Alipay'3+2'system helps enterprises build core competitive advantages
Grey correlation cases and codes
一些小知识点
Task04 mathematical statistics
[recommended algorithm] C interview question of a small factory
All in all, the low code still needs to solve these four problems
LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target