当前位置:网站首页>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;
}
边栏推荐
- 7-5 复数四则运算
- 必杀技--使用FFmpeg命令快速精准剪切视频
- Ficusjs series (I) introduction to ficusjs
- kubernetes集群搭建
- Byte order - how to judge the big end and the small end
- conda环境下pip install 无法安装到指定conda环境中(conda环境的默认pip安装位置)
- How to operate the newly revised Taobao merchants and what should be paid attention to
- ARM处理器模式与寄存器
- IP address management
- Design of tablewithpage
猜你喜欢

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

QML first day

Who moved my package lock

Blue Bridge Cup 2015 CA provincial competition (filling the pit)

寻找两个有序数组的中位数(LeetCode 4)

ARM processor mode and register

UML系列文章(30)体系结构建模---制品图

5g NR Protocol Learning - - ts38.211 downlink channel

QML学习 第一天

Batch load/store instructions of arm instruction set
随机推荐
Reprint --win10 open the task manager to solve the blue screen problem
ARM指令集之Load/Store访存指令(二)
TinyMCE series (I) TinyMCE environment construction
The second day of QML study
为什么新品发布上架之后会没有流量,新品应该怎么发布?
机器学习之线性模型
VirtualBox virtual machine shut down due to abnormal system. The virtual machine startup item is missing
Channel Shuffle类
Why is there no traffic after the launch of new products? How should new products be released?
5g NR protocol learning -- ts38.211 downlink channel
Relatively rare exception records in UI automation test
5G NR协议学习--TS38.211下行通道
创建Servlet项目
Decision tree of machine learning
邻居子系统之邻居项状态更新
[cf1392d] D. Omkar and bed Wars
Rich text editor copying pictures in word documents
ARM指令集之Load/Store指令寻址方式(二)
How to select standard products and non-standard products, the importance of selection, and how to layout the store
NVIDIA Jetson Nano Developer Kit 入门