4-adjacent(AtCoder-2686)
Problem Description
We have a sequence of length N, a=(a1,a2,…,aN). Each ai is a positive integer.
Snuke's objective is to permute the element in a so that the following condition is satisfied:
For each 1≤i≤N−1, the product of ai and ai+1 is a multiple of 4.
Determine whether Snuke can achieve his objective.Constraints
- 2≤N≤105
- ai is an integer.
- 1≤ai≤109
Input
Input is given from Standard Input in the following format:
N
a1 a2 … aNOutput
If Snuke can achieve his objective, print Yes; otherwise, print No.
Example
Sample Input 1
3
1 10 100Sample Output 1
Yes
One solution is (1,100,10).Sample Input 2
4
1 2 3 4Sample Output 2
No
It is impossible to permute a so that the condition is satisfied.Sample Input 3
3
1 4 1Sample Output 3
Yes
The condition is already satisfied initially.Sample Input 4
2
1 1Sample Output 4
No
Sample Input 5
6
2 7 1 8 2 8Sample Output 5
Yes
题意:给出 n 个数,问经过任意次交换后,使得每个数乘以他的左边是 4 的倍数,乘以右边也是 4 的倍数,若能成功输出 Yes,若不能输出 No
思路:
由于每个数乘以相邻的数是 4 的倍数,那么说明其中一个数是 4 的倍数,或者两个数都是 2 的倍数
因此,直接统计这 n 个数中为 2、4 的倍数的数的个数,考虑每个位置插 2 插 4 的关系即可
Source Program
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 200000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
int a[N];
int main() {int n;scanf("%d",&n);int num4=0,num2=0;for(int i=1;i<=n;i++){scanf("%d",&a[i]);if(a[i]%4==0)num4++;else if(a[i]%2==0)num2++;}if(n>2*num4+num2+1)printf("No\n");else if(2*num4+num2+1==n&&num2!=0)printf("No\n");elseprintf("Yes\n");return 0;
}
4-adjacent(AtCoder-2686)相关推荐
- AtCoder Beginner Contest 198 (A ~ F)题解
目录 A. Div B. Palindrome with leading zeros C. Compass Walking D. Send More Money E. Unique Color F. ...
- UPC个人训练赛第十五场(AtCoder Grand Contest 031)
传送门: [1]:AtCoder [2]:UPC比赛场 [3]:UPC补题场 参考资料 [1]:https://www.cnblogs.com/QLU-ACM/p/11191644.html B.Re ...
- Mynavi Programming Contest 2021(AtCoder Beginner Contest 201)题解
文章目录 A - Tiny Arithmetic Sequence B - Do you know the second highest mountain? C - Secret Number D - ...
- KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200)题解
文章目录 A - Century B - 200th ABC-200 C - Ringo's Favorite Numbers 2 D - Happy Birthday! 2 E - Patisser ...
- freee Programming Contest 2022(AtCoder Beginner Contest 264)A~D题详细讲解
目录 博主赛情 网站链接 比赛简介 Contest Information Reason why freee needs AtCoder users freee's business content ...
- hadoop生态搭建(3节点)-06.hbase配置
# http://archive.apache.org/dist/hbase/1.2.4/ # ==================================================== ...
- 干货|(DL~3)deep learning中一些层的介绍
点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 简介 一.relu层 1.前向传播 2.反向传播 二.dropou ...
- 【解题报告系列】超高质量题单 + 题解(ACM / OI)超高质量题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我新写的超高质量的题解和代码,题目难度不 ...
- HL7 Figure 2-1. Delimiter values(分隔符值)
Figure 2-1. Delimiter values(分隔符值) Delimiter 分隔符 Suggested Value 假定值 Encoding Character Position 编码 ...
- 【2019牛客暑期多校训练营(第二场) - D】Kth Minimum Clique(bfs,tricks)
题干: 链接:https://ac.nowcoder.com/acm/contest/882/D 来源:牛客网 Given a vertex-weighted graph with N vertice ...
最新文章
- python之路--网络编程之socket
- 日文 LaTeX 系统介绍 - 最简示例
- 【转】子网划分实例与讲解
- 网络调试指令ping、telnet、curl
- Spring MVC中的拦截器/过滤器HandlerInterceptorAdapter的使用
- 小汤学编程之JAVA基础day10——常用类(二):String常用方法、正则、StringBuffer和StringBuilder、Math和Random类、日期类和数字类
- oracle脏块,检查点队列上的最早脏的数据块再次被修改以何种顺序刷到磁盘
- Delphi – 我的代码之简单五子棋
- Google发布Puppeteer 1.0
- 23种设计模式(6):模版方法模式
- 单循环赛积分至少多少才能保证一定出线?
- 阿里云php探针,X 探针(刘海探针)开源 PHP 探针介绍
- RSD的遥感图像合成工具
- 小学计算机期末评价方案,小学班级管理评价方案
- python islower方法_(验证)Python中不同类型的islower()方法
- 口模块型3500/22-01-01-00
- 桌面视频录制软件有哪些?怎么简单又快地录制视频?
- Candence学习篇(7)allegro pcb editor 17.2如何打开旧版本.brd和.dra文件等
- 华为OD机试 - 士兵过河
- 瞄准大鱼号这八种收益,让你轻松月入过万