当前位置:网站首页>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;
}
边栏推荐
- K-Means Clustering Visualization in R: Step By Step Guide
- How to Add P-Values onto Horizontal GGPLOTS
- GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT
- How does Premiere (PR) import the preset mogrt template?
- Bedtools tutorial
- Mish shake the new successor of the deep learning relu activation function
- GGHIGHLIGHT: EASY WAY TO HIGHLIGHT A GGPLOT IN R
- Le tutoriel F - String le plus facile à comprendre de l'histoire.
- FLESH-DECT(MedIA 2021)——一个material decomposition的观点
- File operation (detailed!)
猜你喜欢

GGHIGHLIGHT: EASY WAY TO HIGHLIGHT A GGPLOT IN R

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

A sharp tool for exposing data inconsistencies -- a real-time verification system

Natural language processing series (II) -- building character level language model using RNN

2022年遭“挤爆”的三款透明LED显示屏

机械臂速成小指南(七):机械臂位姿的描述方法

Power Spectral Density Estimates Using FFT---MATLAB

Cluster Analysis in R Simplified and Enhanced

基于Arduino和ESP8266的连接手机热点实验(成功)

Filtre de profondeur de la série svo2
随机推荐
Time format display
Log4j2
机械臂速成小指南(七):机械臂位姿的描述方法
PyTorch nn.RNN 参数全解析
行业的分析
ESP32 Arduino 引入LVGL 碰到的一些问题
Take you ten days to easily finish the finale of go micro services (distributed transactions)
R HISTOGRAM EXAMPLE QUICK REFERENCE
B high and beautiful code snippet sharing image generation
HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R
PX4 Position_Control RC_Remoter引入
This article takes you to understand the operation of vim
Easyexcel and Lombok annotations and commonly used swagger annotations
Bedtools tutorial
R HISTOGRAM EXAMPLE QUICK REFERENCE
A sharp tool for exposing data inconsistencies -- a real-time verification system
to_ Bytes and from_ Bytes simple example
PHP 2D and multidimensional arrays are out of order, PHP_ PHP scrambles a simple example of a two-dimensional array and a multi-dimensional array. The shuffle function in PHP can only scramble one-dim
The computer screen is black for no reason, and the brightness cannot be adjusted.
数据分析 - matplotlib示例代码