当前位置:网站首页>Codeforces Round #771 (Div. 2)(A-C)
Codeforces Round #771 (Div. 2)(A-C)
2022-07-02 19:58:00 【eyuhaobanga】
Array interval inversion , Let me deeply understand the meaning of the minimum order of a wave of dictionaries , The front one is as small as possible , The latter doesn't matter , During the game, always look for the interval with the largest inverse ordinal number before the reversal wa dead , This question only needs to reverse the interval where the reverse order number first appears
AC Code :
/* Tips: 1.int? long long? 2.don't submit wrong answer 3.figure out logic first, then start writing please 4.know about the range 5.check if you have to input t or not 6.modulo of negative numbers is not a%b, it is a%b + abs(b) */ #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x) & -(x)) #define endl '\n' #define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef vector<int> vi; typedef vector<long long> vll; typedef vector<char> vc; typedef long long ll; template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template<class T> T power(T a, int b) { T res = 1; for (; b; b >>= 1, a = a * a) { if (b & 1) { res = res * a; } } return res; } template <typename T> inline void read(T& x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); } x *= f; } const int INF = 0x3f3f3f3f; const int mod = 1000000007; const double PI = acos(-1.0); const double eps = 1e-6; inline int sgn(double x) { return x < -eps ? -1 : x > eps; } void solve() { int n; cin >> n; vector<int> a(n + 5); for (int i = 0; i < n; i++) { cin >> a[i]; } int x = 0; while (x < n && a[x] == x + 1) { x++; } if (x < n) { int y = x; while (a[y] != x + 1) { y++; } reverse(a.begin() + x, a.begin() + y + 1); } for (int i = 0; i < n; i++) { cout << a[i] << " \n"[i == n - 1]; } return; } int main() { IOS1; //IOS2; int __t = 1; cin >> __t; for (int _t = 1; _t <= __t; _t++) { solve(); } return 0; } /* */B At first glance, the question seems to be doing bubble sorting, but it only needs the sum of two numbers to be odd in order to exchange , It's not , The question should be T Lost a lot of people , We only need to divide odd numbers and even numbers into two sets , Judge whether the two sets are well ordered , Because if there is a set that is not well ordered , Know odd numbers + Odd number = even numbers , even numbers + even numbers = even numbers , So in any case, two numbers with the same property cannot be exchanged , In the end, it is impossible to put everything in order , In contrast, if the two sets are in order , Exchange the small one forward , The big ones are exchanged back , Odd number + even numbers = Odd number
AC Code :
/* Tips: 1.int? long long? 2.don't submit wrong answer 3.figure out logic first, then start writing please 4.know about the range 5.check if you have to input t or not 6.modulo of negative numbers is not a%b, it is a%b + abs(b) */ #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x) & -(x)) #define endl '\n' #define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef vector<int> vi; typedef vector<long long> vll; typedef vector<char> vc; typedef long long ll; template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template<class T> T power(T a, int b) { T res = 1; for (; b; b >>= 1, a = a * a) { if (b & 1) { res = res * a; } } return res; } template <typename T> inline void read(T& x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); } x *= f; } const int INF = 0x3f3f3f3f; const int mod = 1000000007; const double PI = acos(-1.0); const double eps = 1e-6; inline int sgn(double x) { return x < -eps ? -1 : x > eps; } void solve() { int n; cin >> n; vector<int> odd, even; for (int i = 0; i < n; i++) { int x; cin >> x; if (x % 2 == 1) { odd.push_back(x); } else { even.push_back(x); } } if (is_sorted(odd.begin(), odd.end()) && is_sorted(even.begin(), even.end())) { cout << "Yes" << endl; } else { cout << "No" << endl; } return; } int main() { IOS1; //IOS2; int __t = 1; cin >> __t; for (int _t = 1; _t <= __t; _t++) { solve(); } return 0; } /* */From the meaning of the title, we can know when ai Greater than ai+1 when ai and ai+1 You can connect a path , The point that can be reached through a continuous path is an independent set , Ask how many different sets there are in the end , Because the numbers in the array are 1 To n One of the full permutations of , So we have to deal with it before i Maximum number max, Because when i=max It shows that all the previous numbers can form an independent set, and the numbers in it must be less than or equal to i, And the latter numbers must be greater than i as well as i The number in front , Therefore, it is impossible to form a pathway , Otherwise, there must be more than max Smaller numbers , Then there must be other paths for them to form a connected graph
AC Code :
/* Tips: 1.int? long long? 2.don't submit wrong answer 3.figure out logic first, then start writing please 4.know about the range 5.check if you have to input t or not 6.modulo of negative numbers is not a%b, it is a%b + abs(b) */ #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x) & -(x)) #define endl '\n' #define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef vector<int> vi; typedef vector<long long> vll; typedef vector<char> vc; typedef long long ll; template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template<class T> T power(T a, int b) { T res = 1; for (; b; b >>= 1, a = a * a) { if (b & 1) { res = res * a; } } return res; } template <typename T> inline void read(T& x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); } x *= f; } const int INF = 0x3f3f3f3f; const int mod = 1000000007; const double PI = acos(-1.0); const double eps = 1e-6; inline int sgn(double x) { return x < -eps ? -1 : x > eps; } void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int ans = 0; int maxx = 0; for (int i = 0; i < n; i++) { maxx = max(maxx, a[i]); if (maxx == i + 1) { ans += 1; } } cout << ans << endl; return; } int main() { IOS1; //IOS2; int __t = 1; cin >> __t; for (int _t = 1; _t <= __t; _t++) { solve(); } return 0; } /* */
边栏推荐
- AcWing 1127. Sweet butter solution (shortest path SPFA)
- Understanding and function of polymorphism
- Zabbix5 client installation and configuration
- 励志!大凉山小伙全奖直博!论文致谢看哭网友
- 面试经验总结,为你的offer保驾护航,满满的知识点
- B端电商-订单逆向流程
- Embedded (PLD) series, epf10k50rc240-3n programmable logic device
- Istio1.12: installation and quick start
- CRM Customer Relationship Management System
- SQLite 3.39.0 发布,支持右外连接和全外连接
猜你喜欢

How to do interface testing? After reading this article, it will be clear

API documentation tool knife4j usage details

After 65 days of closure and control of the epidemic, my home office experience sharing | community essay solicitation

Development skills of rxjs observable custom operator

KT148A语音芯片ic的开发常见问题以及描述

Shardingsphere jdbc5.1.2 about select last_ INSERT_ ID () I found that there was still a routing problem

Implementation of online shopping mall system based on SSM

有时候只查询一行语句,执行也慢

upload-labs

MySQL function
随机推荐
For (Auto A: b) and for (Auto & A: b) usage
AcWing 340. Solution to communication line problem (binary + double ended queue BFS for the shortest circuit)
GCC: Graph Contrastive Coding for Graph Neural NetworkPre-Training
Infix expression is converted to suffix expression (C language code + detailed explanation)
Introduction to program ape (XII) -- data storage
在消费互联网时代,诞生了为数不多的头部平台的话
c语言里怎么设立优先级,细说C语言优先级
VBScript详解(一)
Solution to blue screen after installing TIA botu V17 in notebook
Kt148a voice chip instructions, hardware, protocols, common problems, and reference codes
分享几个图床网址,便于大家分享图片
【Hot100】22. 括号生成
rxjs Observable 自定义 Operator 的开发技巧
B-end e-commerce - reverse order process
Workplace four quadrant rule: time management four quadrant and workplace communication four quadrant "suggestions collection"
B端电商-订单逆向流程
自動生成VGG圖像注釋文件
JASMINER X4 1U deep disassembly reveals the secret behind high efficiency and power saving
In the era of consumer Internet, a few head platforms have been born
AcWing 1128. Messenger solution (shortest path Floyd)