当前位置:网站首页>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;
}
边栏推荐
- Depth filter of SvO2 series
- Seriation in R: How to Optimally Order Objects in a Data Matrice
- GGPlot Examples Best Reference
- Pyqt5+opencv project practice: microcirculator pictures, video recording and manual comparison software (with source code)
- R HISTOGRAM EXAMPLE QUICK REFERENCE
- Fabric.js 3个api设置画布宽高
- conda常用命令汇总
- Summary of flutter problems
- 行業的分析
- How to Easily Create Barplots with Error Bars in R
猜你喜欢
[QT] Qt development environment installation (QT version 5.14.2 | QT download | QT installation)
GGPlot Examples Best Reference
YYGH-BUG-05
6. Introduce you to LED soft film screen. LED soft film screen size | price | installation | application
XSS labs master shooting range environment construction and 1-6 problem solving ideas
Power Spectral Density Estimates Using FFT---MATLAB
深入理解P-R曲线、ROC与AUC
vant tabs组件选中第一个下划线位置异常
How to Create a Nice Box and Whisker Plot in R
Cluster Analysis in R Simplified and Enhanced
随机推荐
6. Introduce you to LED soft film screen. LED soft film screen size | price | installation | application
文件操作(详解!)
史上最易懂的f-string教程,收藏這一篇就够了
YYGH-10-微信支付
Three transparent LED displays that were "crowded" in 2022
excel表格中选中单元格出现十字带阴影的选中效果
ORB-SLAM2不同线程间的数据共享与传递
SVO2系列之深度滤波DepthFilter
[untitled] how to mount a hard disk in armbian
How to Add P-Values onto Horizontal GGPLOTS
K-Means Clustering Visualization in R: Step By Step Guide
Visualization of chip SEQ data by deeptools
PX4 Position_ Control RC_ Remoter import
Log4j2
The position of the first underline selected by the vant tabs component is abnormal
php 二维、多维 数组打乱顺序,PHP_php打乱数组二维数组多维数组的简单实例,php中的shuffle函数只能打乱一维
Dynamic debugging of multi file program x32dbg
vant tabs组件选中第一个下划线位置异常
HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R
Pyqt5+opencv project practice: microcirculator pictures, video recording and manual comparison software (with source code)