当前位置:网站首页>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
边栏推荐
- [shutter] shutter layout component (opacity component | clipprect component | padding component)
- Redis分布式锁故障,我忍不住想爆粗...
- qwb2018_ core kernel_ rop
- 7. Build native development environment
- Welfare | Pu Aries | liv heart co branded Plush surrounding new products are on the market!
- 股票开户要找谁?手机开户是安全么?
- Adding data to the head or tail of the rar file can still decompress normally
- Research Report on micro vacuum pump industry - market status analysis and development prospect prediction
- Go web programming practice (1) -- basic syntax of go language
- In depth research and investment feasibility report on the global and China active vibration isolation market 2022-2028
猜你喜欢
The web version of xshell supports FTP connection and SFTP connection [detailed tutorial] continued from the previous article
[shutter] shutter layout component (physicalmodel component)
[shutter] shutter layout component (fractionallysizedbox component | stack layout component | positioned component)
rwctf2022_ QLaaS
关于测试用例
[shutter] statefulwidget component (floatingactionbutton component | refreshindicator component)
[shutter] statefulwidget component (bottom navigation bar component | bottomnavigationbar component | bottomnavigationbaritem component | tab switching)
[shutter] shutter layout component (opacity component | clipprect component | padding component)
Report on investment development and strategic recommendations of China's vibration isolator market, 2022-2027
treevalue——Master Nested Data Like Tensor
随机推荐
Volvo's first MPV is exposed! Comfortable and safe, equipped with 2.0T plug-in mixing system, it is worth first-class
Centos7 installation and configuration of redis database
China's noise meter market trend report, technical dynamic innovation and market forecast
Construction and maintenance of business websites [6]
Off chip ADC commissioning record
Construction and maintenance of business websites [8]
[Yu Yue education] reference materials of analog electronic technology of Nanjing Institute of information technology
[shutter] statefulwidget component (pageview component)
Redis -- three special data types
Adding data to the head or tail of the rar file can still decompress normally
Research Report on right-hand front door industry - market status analysis and development prospect forecast
MySQL learning record (4)
Research Report on market supply and demand and strategy of Chinese garden equipment industry
VictoriaMetrics 简介
Cloud computing technology [1]
Research Report on micro vacuum pump industry - market status analysis and development prospect prediction
Construction and maintenance of business website [3]
Browser - clean up the cache of JS in the page
[CV] Wu Enda machine learning course notes | Chapter 12
Share the easy-to-use fastadmin open source system - Installation