当前位置:网站首页>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
边栏推荐
- Valid @suppresswarnings warning name
- All in all, the low code still needs to solve these four problems
- 网站服务器:好用的网站服务器怎么选这五方面要关注
- Chen Yu (Aqua) - Safety - & gt; Cloud Security - & gt; Multicloud security
- (12) Somersault cloud case (navigation bar highlights follow)
- How to choose the right server for website data collection?
- 2022 question bank and answers for safety production management personnel of hazardous chemical production units
- 2022 t elevator repair new version test questions and t elevator repair simulation test question bank
- OSPF notes [multiple access, two multicast addresses with OSPF]
- Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
猜你喜欢

283. move zero

The junior college students were angry for 32 days, four rounds of interviews, five hours of soul torture, and won Ali's offer with tears

软件研发的十大浪费:研发效能的另一面

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

MySQL winter vacation self-study 2022 12 (5)

Odeint and GPU

LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
![[human version] Web3 privacy game in the dark forest](/img/89/e16789b7f3892002748aab309c45e6.png)
[human version] Web3 privacy game in the dark forest

LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver

Hololens2 development environment building and deploying apps
随机推荐
Embedded System Development Notes 79: why should I get the IP address of the local network card
Knowledge supplement: redis' basic data types and corresponding commands
多次跳槽后,月薪等于老同事的年薪
如何看待智慧城市建设中的改变和机遇?
Class and object finalization
Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling
Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and
嵌入式系统开发笔记81:使用Dialog组件设计提示对话框
Threejs opening
Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
Chen Yu (Aqua) - Safety - & gt; Cloud Security - & gt; Multicloud security
Knowledge supplement: basic usage of redis based on docker
Internet winter, how to spend three months to make a comeback
Grey correlation cases and codes
测量三相永磁同步电机的交轴直轴电感
Mallbook: how can hotel enterprises break the situation in the post epidemic era?
206. reverse linked list
Extension fragment
JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition