当前位置:网站首页>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;
}
边栏推荐
- Who moved my package lock
- How to operate the newly revised Taobao merchants and what should be paid attention to
- Reentrantlock source code analysis
- 6.6 RL:MDP及奖励函数
- Blue Bridge Cup 2015 CA provincial competition (filling the pit)
- Doris records service interface calls
- Shardingjdbc-5.1.0 monthly horizontal table splitting + read-write separation, automatic table creation and node table refresh
- ARM指令集之数据处理指令寻址方式
- Process creation and recycling
- 5g NR Protocol Learning - - ts38.211 downlink channel
猜你喜欢
随机推荐
Spark common encapsulation classes
TinyMCE series (III) introduction to common TinyMCE APIs
Deep learning and CV tutorial (14) | image segmentation (FCN, segnet, u-net, pspnet, deeplab, refinenet)
Pytorch笔记
Cookies and sessions
5G NR协议学习--TS38.211下行通道
LeetCode_二分搜索_中等_162. 寻找峰值
ARM指令集之批量Load/Store指令
6.6 分離卷積
Asynchronous path processing
5G NR協議學習--TS38.211下行通道
单元测试用例框架--unittest
TinyMCE series (II) TinyMCE plug-in development
Pseudo instruction of arm instruction set
Logrotate log rotation method create and copyruncate principles
机器学习基础概念
Process creation and recycling
视频分类的类间和类内关系——正则化
ARM指令集之数据处理类指令
PIP install in the CONDA environment cannot be installed into the specified CONDA environment (the default PIP installation location of the CONDA environment)









