当前位置:网站首页>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;
}
边栏推荐
- Node crawler puppeter usage
- Blue Bridge Cup 2015 CA provincial competition (filling the pit)
- B.刷墙(C语言)
- 邻居子系统之邻居项状态更新
- LeetCode_二分搜索_中等_162. 寻找峰值
- Design of secure chat tool based on C #
- Pseudo instruction of arm instruction set
- Manuscript manuscript format preparation
- 6.6 分离卷积
- How to select standard products and non-standard products, the importance of selection, and how to layout the store
猜你喜欢

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

mysql复习

Asynchronous path processing

QT adds a summary of the problems encountered in the QObject class (you want to use signals and slots) and solves them in person. Error: undefined reference to `vtable for xxxxx (your class name)‘

6.6 分离卷积

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

視頻分類的類間和類內關系——正則化

Reentrantlock source code analysis

UML series articles (30) architecture modeling -- product diagram

ARM处理器模式与寄存器
随机推荐
【数据库】sqlite版本升级、降级
Reprint --win10 open the task manager to solve the blue screen problem
Pytorch笔记
5g NR protocol learning -- ts38.211 downlink channel
Load/store instruction addressing mode of arm instruction set (1)
TinyMCE realizes automatic uploading of pasted pictures
Record the pits encountered when using JPA
【深度学习基础】神经网络的学习(4)
How to select standard products and non-standard products, the importance of selection, and how to layout the store
ARM指令集之Load/Store访存指令(二)
[database] SQLite version upgrade and downgrade
A.前缀极差
6.6 separate convolution
LeetCode 497. 非重叠矩形中的随机点(前缀和+二分)
kubernetes集群搭建
Socket implements TCP communication flow
【QNX Hypervisor 2.2 用户手册】4 构建QNX Hypervisor系统
PIP install in the CONDA environment cannot be installed into the specified CONDA environment (the default PIP installation location of the CONDA environment)
Multiplication instruction of arm instruction set
机器学习之决策树