当前位置:网站首页>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;
}
边栏推荐
- The selected cells in Excel form have the selection effect of cross shading
- YYGH-9-预约下单
- Cluster Analysis in R Simplified and Enhanced
- Log4j2
- Some problems encountered in introducing lvgl into esp32 Arduino
- YYGH-BUG-05
- 【多线程】主线程等待子线程执行完毕在执行并获取执行结果的方式记录(有注解代码无坑)
- php 根据经纬度查询距离
- Orb-slam2 data sharing and transmission between different threads
- 深入理解PyTorch中的nn.Embedding
猜你喜欢

数据分析 - matplotlib示例代码

How does Premiere (PR) import the preset mogrt template?

小程序链接生成

Deep understanding of NN in pytorch Embedding

文件操作(详解!)

H5,为页面添加遮罩层,实现类似于点击右上角在浏览器中打开

HOW TO ADD P-VALUES TO GGPLOT FACETS

Esp32 audio frame esp-adf add key peripheral process code tracking

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

HOW TO ADD P-VALUES TO GGPLOT FACETS
随机推荐
[QT] Qt development environment installation (QT version 5.14.2 | QT download | QT installation)
xss-labs-master靶场环境搭建与1-6关解题思路
GGHIGHLIGHT: EASY WAY TO HIGHLIGHT A GGPLOT IN R
GGPlot Examples Best Reference
A sharp tool for exposing data inconsistencies -- a real-time verification system
SCM power supply
How to Create a Beautiful Plots in R with Summary Statistics Labels
Orb-slam2 data sharing and transmission between different threads
Industry analysis
H5, add a mask layer to the page, which is similar to clicking the upper right corner to open it in the browser
自然语言处理系列(三)——LSTM
easyExcel和lombok注解以及swagger常用注解
Time format display
Enter the top six! Boyun's sales ranking in China's cloud management software market continues to rise
自然语言处理系列(一)——RNN基础
Applet link generation
PyTorch搭建LSTM实现服装分类(FashionMNIST)
PX4 Position_ Control RC_ Remoter import
Bedtools tutorial
HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R