当前位置:网站首页>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
边栏推荐
- Get weekday / day of week for datetime column of dataframe - get weekday / day of week for datetime column of dataframe
- [shutter] statefulwidget component (image component | textfield component)
- PIP version update timeout - download using domestic image
- Read a doctor, the kind that studies cows! Dr. enrollment of livestock technology group of Leuven University, milk quality monitoring
- The neo4j skill tree was officially released to help you easily master the neo4j map database
- D4: unpaired image defogging, self enhancement method based on density and depth decomposition (CVPR 2022)
- Accounting regulations and professional ethics [17]
- Plastic granule Industry Research Report - market status analysis and development prospect forecast
- I drew a Gu ailing with characters!
- 暑期第一周总结
猜你喜欢
It is said that this year gold three silver four has become gold one silver two..
In depth research and investment feasibility report of global and Chinese isolator industry, 2022-2028
The web version of xshell supports FTP connection and SFTP connection [detailed tutorial] continued from the previous article
26 FPS video super-resolution model DAP! Output 720p Video Online
Huawei Hongmeng watch achieves fireworks display effect on New Year's Eve
MySQL learning record (6)
How to test the process of restoring backup files?
D4:非成对图像去雾,基于密度与深度分解的自增强方法(CVPR 2022)
Basic knowledge of tree and binary tree (detailed illustration)
MySQL learning record (5)
随机推荐
[shutter] statefulwidget component (floatingactionbutton component | refreshindicator component)
[shutter] statefulwidget component (create statefulwidget component | materialapp component | scaffold component)
Unexpectedly, there are such sand sculpture code comments! I laughed
China plastic bottle and container market trend report, technological innovation and market forecast
MySQL learning record (9)
Market trend report, technical dynamic innovation and market forecast of China's low gloss instrument
Sword finger offer (I) -- handwriting singleton mode
Research Report on market supply and demand and strategy of China's Plastic Geogrid industry
In depth research and investment feasibility report of global and Chinese isolator industry, 2022-2028
AES encryption CBC mode pkcs7padding filling Base64 encoding key 32byte iv16byte
Market trend report, technical innovation and market forecast of China's Micro pliers
China's crude oil heater market trend report, technological innovation and market forecast
MySQL learning record (7)
When Valentine's Day falls on Monday
Three chess games
Basic IO interface technology - microcomputer Chapter 7 Notes
Centos7 installation and configuration of redis database
Cloud computing technology [1]
[shutter] statefulwidget component (pageview component)
Interpretation of some papers published by Tencent multimedia laboratory in 2021