当前位置:网站首页>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
边栏推荐
- ~90z axis translation
- Codeworks global round 19 (CF 1637) a ~ e problem solution
- Three chess games
- Investment strategy analysis of China's electronic information manufacturing industry and forecast report on the demand outlook of the 14th five year plan 2022-2028 Edition
- [shutter] shutter layout component (fractionallysizedbox component | stack layout component | positioned component)
- Micro SD Card Industry Research Report - market status analysis and development prospect forecast
- Import a large amount of data to redis in shell mode
- Basic IO interface technology - microcomputer Chapter 7 Notes
- Redis -- three special data types
- ~91 rotation
猜你喜欢

In depth research and investment feasibility report of global and Chinese isolator industry, 2022-2028
![[use of pointer and pointer and array]](/img/dd/8017215c54aebcdf5c67e46e795d3b.jpg)
[use of pointer and pointer and array]

D4: unpaired image defogging, self enhancement method based on density and depth decomposition (CVPR 2022)

7. Build native development environment

rwctf2022_ QLaaS

MySQL learning record (7)
![The web version of xshell supports FTP connection and SFTP connection [detailed tutorial] continued from the previous article](/img/8f/6759b4685a129f9d10d6ea1dc8e61e.jpg)
The web version of xshell supports FTP connection and SFTP connection [detailed tutorial] continued from the previous article
![[shutter] shutter layout component (opacity component | clipprect component | padding component)](/img/6b/4304be6a4c5427dcfc927babacb4d7.jpg)
[shutter] shutter layout component (opacity component | clipprect component | padding component)

System (hierarchical) clustering method and SPSS implementation

Share the easy-to-use fastadmin open source system - Installation
随机推荐
Construction and maintenance of business website [3]
Cloud computing technology [2]
MySQL installation failed -gpg verification failed
Codeworks global round 19 (CF 1637) a ~ e problem solution
Report on investment development and strategic recommendations of China's vibration isolator market, 2022-2027
Free open source web version of xshell [congratulations on a happy new year]
Basic knowledge of tree and binary tree (detailed illustration)
Redis -- three special data types
Common authority query instructions in Oracle
MySQL learning record (6)
beginning
Construction and maintenance of business websites [4]
3DES (deSede) encryption CBC mode pkcs7padding filling Base64 encoding key 24byte iv8byte
Plastic granule Industry Research Report - market status analysis and development prospect forecast
Accounting regulations and professional ethics [19]
Capacity expansion mechanism of ArrayList
I drew a Gu ailing with characters!
Read a doctor, the kind that studies cows! Dr. enrollment of livestock technology group of Leuven University, milk quality monitoring
[use of pointer and pointer and array]
rwctf2022_ QLaaS