当前位置:网站首页>B.Odd Swap Sort(Codeforces Round #771 (Div. 2))
B.Odd Swap Sort(Codeforces Round #771 (Div. 2))
2022-07-02 21:41:00 【Woodenman Du】
This time cf Can also write A~C,B Question hung up , So make up
Links to questions :https://codeforces.com/contest/1638/problem/B
The question :
Given length is n Array of
What can be done : If a[i]+a[i+1] (1 <= i <= n) It's an odd number , You can swap(a[i],a[i+1])
Now I ask if you can operate through this ( No limit of times ) Change the original array into a completely ascending array
analysis :
This question hangs
At first sight , This is a bubble sort with a condition added , Then it was written like this , The pre-test is over , But I didn't expect a total of 8 Group data , Only four groups were tested last night .....
The next analysis :
The addition of numbers with the same parity must be even
That is to say, in the sub sequence of odd elements and even elements of the array , The relative position of elements cannot be changed , As for the even and odd numbers , Even if the size and position are wrong , They are all adjustable .
So the idea is to check whether the sub sequence of odd elements and even elements of the array are originally ordered
AC Code:
#include<bits/stdc++.h>
using namespace std;
int t,n,x;
void solve()
{
bool ans = true;
cin >>n;
int ji,ou;
ji = ou = -1;
for(int i = 1; i <= n; i++){
cin >>x;
if(x & 1){
if(x < ji) ans = false;
else ji = x;
}
else{
if(x < ou) ans = false;
else ou = x;
}
}
if(ans) cout <<"YES" <<endl;
else cout <<"NO" <<endl;
}
int main(void)
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >>t;
while(t--) solve();
return 0;
} I have to say that this question has last year ICPC Nanjing station C I feel it
边栏推荐
- Cloud computing technology [2]
- One week dynamics of dragon lizard community | 2.07-2.13
- MySQL installation failed -gpg verification failed
- Research Report on market supply and demand and strategy of China's right-hand outward rotation entry door industry
- 关于测试用例
- Add two numbers of leetcode
- Off chip ADC commissioning record
- China's log saw blade market trend report, technological innovation and market forecast
- Browser - clean up the cache of JS in the page
- China plastic bottle and container market trend report, technological innovation and market forecast
猜你喜欢

Read a doctor, the kind that studies cows! Dr. enrollment of livestock technology group of Leuven University, milk quality monitoring

6 pyspark Library

Basic IO interface technology - microcomputer Chapter 7 Notes

MySQL learning record (9)
![[shutter] statefulwidget component (bottom navigation bar component | bottomnavigationbar component | bottomnavigationbaritem component | tab switching)](/img/a7/0b87fa45ef2edd6fac519b40adbeae.gif)
[shutter] statefulwidget component (bottom navigation bar component | bottomnavigationbar component | bottomnavigationbaritem component | tab switching)

Redis distributed lock failure, I can't help but want to burst

PIP version update timeout - download using domestic image

MySQL learning record (5)

The neo4j skill tree was officially released to help you easily master the neo4j map database

MySQL learning record (7)
随机推荐
Interpretation of some papers published by Tencent multimedia laboratory in 2021
Share the easy-to-use fastadmin open source system - Installation
7. Build native development environment
Accounting regulations and professional ethics [17]
基本IO接口技术——微机第七章笔记
Check the confession items of 6 yyds
Analysis of neural network
Welfare | Pu Aries | liv heart co branded Plush surrounding new products are on the market!
Hot backup routing protocol (HSRP)
MySQL installation failed -gpg verification failed
Cardinality sorting (detailed illustration)
Structured text language XML
Construction and maintenance of business website [2]
treevalue——Master Nested Data Like Tensor
Construction and maintenance of business website [1]
PIP version update timeout - download using domestic image
China's Micro SD market trend report, technology dynamic innovation and market forecast
Cloud computing technology [1]
MySQL learning record (9)
Get weekday / day of week for datetime column of dataframe - get weekday / day of week for datetime column of dataframe