当前位置:网站首页>Codeforces 771 div2 B (no one FST, refers to himself)
Codeforces 771 div2 B (no one FST, refers to himself)
2022-07-02 12:01:00 【Find a derivative first】
subject
The question : Given length is n Array of a, It is allowed to exchange two adjacent and odd numbers any time , Determine whether the array can be made non descending .
Ideas : Violent simulation , I feel a little silly indeed ,2222211111, achieve n Fang . sure T, But I didn't expect the positive solution at that time , Buried .
As long as the parity is different, it can be exchanged , We don't need to care about different parity , It can be changed anyway .
How to judge no solution ? Two numbers with the same parity , And there is an inverse relationship , Direct mail .
Therefore, the current last odd number can be maintained dynamically 、 Even values , If there is an inverse relationship , unsolvable . Otherwise , Through several exchanges, the preceding numbers can be arranged in order .
Time complexity : O(n)
Code :
// Problem: B. Odd Swap Sort
// Contest: Codeforces - Codeforces Round #771 (Div. 2)
// URL: https://codeforces.com/contest/1638/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<complex>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<list>
#include<set>
#include<queue>
#include<stack>
#define OldTomato ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define fir(i,a,b) for(int i=a;i<=b;++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define p_ priority_queue
// round() rounding ceil() Rounding up floor() Rounding down
// lower_bound(a.begin(),a.end(),tmp,greater<ll>()) First less than or equal to
// #define int long long //QAQ
using namespace std;
typedef complex<double> CP;
typedef pair<int,int> PII;
typedef long long ll;
// typedef __int128 it;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll inf = 1e18;
const int N = 2e5+10;
const int M = 1e6+10;
const int mod = 1e9+7;
const double eps = 1e-6;
inline int lowbit(int x){
return x&(-x);}
template<typename T>void write(T x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)
{
write(x/10);
}
putchar(x%10+'0');
}
template<typename T> void read(T &x)
{
x = 0;char ch = getchar();ll f = 1;
while(!isdigit(ch)){
if(ch == '-')f*=-1;ch=getchar();}
while(isdigit(ch)){
x = x*10+ch-48;ch=getchar();}x*=f;
}
int n,m,k,T;
int last[2];
void solve()
{
read(n);
bool flag = true;
last[0] = last[1] = 0;
for(int x,i=1;i<=n;++i)
{
read(x);
if(x < last[x&1]) flag = false;
last[x&1] = x;
}
if(flag) puts("Yes");
else puts("No");
}
signed main(void)
{
// T = 1;
// OldTomato; cin>>T;
read(T);
while(T--)
{
solve();
}
return 0;
}
边栏推荐
- 基于Arduino和ESP8266的连接手机热点实验(成功)
- 求16以内正整数的阶乘,也就是n的阶层(0=<n<=16)。输入1111退出。
- HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R
- Time format display
- 动态内存(进阶四)
- Orb-slam2 data sharing and transmission between different threads
- b格高且好看的代码片段分享图片生成
- Take you ten days to easily finish the finale of go micro services (distributed transactions)
- Flesh-dect (media 2021) -- a viewpoint of material decomposition
- Natural language processing series (III) -- LSTM
猜你喜欢

How to Add P-Values onto Horizontal GGPLOTS

小程序链接生成

Seriation in R: How to Optimally Order Objects in a Data Matrice

【2022 ACTF-wp】

Esp32 stores the distribution network information +led displays the distribution network status + press the key to clear the distribution network information (source code attached)

GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT

Small guide for rapid formation of manipulator (VII): description method of position and posture of manipulator
![[visual studio 2019] create MFC desktop program (install MFC development components | create MFC application | edit MFC application window | add click event for button | Modify button text | open appl](/img/6a/111da81436659c7502648907ec1367.jpg)
[visual studio 2019] create MFC desktop program (install MFC development components | create MFC application | edit MFC application window | add click event for button | Modify button text | open appl

Pyqt5+opencv project practice: microcirculator pictures, video recording and manual comparison software (with source code)

H5,为页面添加遮罩层,实现类似于点击右上角在浏览器中打开
随机推荐
SVO2系列之深度濾波DepthFilter
xss-labs-master靶场环境搭建与1-6关解题思路
GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT
How to Visualize Missing Data in R using a Heatmap
to_ Bytes and from_ Bytes simple example
How to Create a Nice Box and Whisker Plot in R
PgSQL string is converted to array and associated with other tables, which are displayed in the original order after matching and splicing
Depth filter of SvO2 series
[geek challenge 2019] upload
史上最易懂的f-string教程,收藏这一篇就够了
R HISTOGRAM EXAMPLE QUICK REFERENCE
Visualization of chip SEQ data by deeptools
How to Visualize Missing Data in R using a Heatmap
Dynamic memory (advanced 4)
How to Add P-Values onto Horizontal GGPLOTS
The computer screen is black for no reason, and the brightness cannot be adjusted.
XSS labs master shooting range environment construction and 1-6 problem solving ideas
ESP32音频框架 ESP-ADF 添加按键外设流程代码跟踪
YYGH-BUG-04
Log4j2