当前位置:网站首页>B. Wall painting (C language)
B. Wall painting (C language)
2022-06-12 11:58:00 【Desert –】
subject


Ideas
First , From the title we can get :
······ Two numbers with the same parity can have the same value by adding building blocks
······ Two adjacent equal numbers can change parity at the same time ( That is to add a horizontal building block to it )
thus , We can get :
······ Odd numbers two numbers with the same parity cannot become exactly equal numbers
······ Even numbers two numbers with the same parity can become exactly equal numbers
therefore :
······ When the number between two numbers with the same parity is even , Then these two numbers and each of them become equal numbers
······ When the number between two numbers with the same parity is an odd number , Then these two numbers and each of them cannot be completely equal
So the problem becomes :
······ Judge whether there are even numbers between two numbers with the same parity , If it is , Then the walls in this area can be the same height ( In other words, the wall in this area can be any height , Adding blocks can change the height ), On the contrary, we can't .
Concrete realization :
There are two cases :
Finally, the height of the wall becomes an odd number : Find two nodes with odd numbers , Judge whether the number between them is even , If it is , Continue to look for the following two odd nodes , Continue to judge , Until all are even numbers , Walls can be the same height ; If not , The walls can't be the same height .
Even number homology .
In the case of even numbers and odd numbers, only one kind of , The wall can be the same height
Be careful : Someone might ask , How to calculate the odd node between the current two odd nodes and the following two odd nodes , Actually , Add several building blocks directly vertically , Can be any odd number ; Even nodes are the same . So these nodes don't matter .
Code
#include<stdio.h>
int n;
int a[500000];
int judge(int x);
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
if(judge(1)||judge(0)){
printf("YES");
}else{
printf("NO");
}
}
int judge(int x)
{
int index=-1;
for(int i=0;i<n;i++){
if(a[i]%2==x){
continue;
}
if(index!=-1){
int len=i-index-1;
if(len%2==1){
return 0;
}
index=-1;
}else{
index=i;
}
}
return index==-1;
}
边栏推荐
- Pytoch notes
- 邻居子系统之ARP协议数据处理过程
- Google Earth Engine(GEE)——Kmeans聚类快速进行土地分类(双for循环快速调参)
- Face recognition PIP failed to install Dlib Library
- 6.6 separate convolution
- QML first day
- 【深度学习基础】神经网络的学习(4)
- Deep learning and CV tutorial (14) | image segmentation (FCN, segnet, u-net, pspnet, deeplab, refinenet)
- IP address management
- 影响店铺权重的三十一条,快来看看中招了吗
猜你喜欢

【深度学习基础】反向传播法(1)

ARM处理器模式与寄存器

PIP install in the CONDA environment cannot be installed into the specified CONDA environment (the default PIP installation location of the CONDA environment)

The second day of QML study

Compiling Draco library on Windows platform

转载--win10打开任务管理器就蓝屏的问题

LeetCode 497. Random points in non overlapping rectangles (prefix and + bisection)

视频分类的类间和类内关系——正则化

5G NR協議學習--TS38.211下行通道

IP地址管理
随机推荐
Ficusjs series (I) introduction to ficusjs
机器学习之线性模型
FPGA Development - Hello_ World routine
Load/store memory access instruction of arm instruction set (1)
单元测试用例框架--unittest
淘宝新改版商家如何操作,需要注意的点有哪些
7-5 复数四则运算
[cf1392d] D. Omkar and bed Wars
Load/store instruction addressing mode of arm instruction set (2)
Compiling Draco library on Windows platform
【深度学习基础】反向传播法(1)
The second day of QML study
Lambda and filter, List 和 numpy array的索引,以及各种距离指标distance-metrics,拼接数组以及axis=0 and axis=1的区分
Create servlet project
Pseudo instruction of arm instruction set
The first thing with a server
Multiplication instruction of arm instruction set
TinyMCE series (IV) introduction to common built-in UI components of TinyMCE
LeetCode 890. 查找和替换模式(模拟+双哈希表)
First understand the onion model, analyze the implementation process of middleware, and analyze the source code of KOA Middleware