题目传送门


分析

直接暴力。

我们可以根据题意进行模拟,使用二重循环即可。


代码讲解

  1. 定义变量\(n\)和计数数组\(cnt\),再定义数组\(a\)并输入。
	int a[1000000];
int n,cnt=0;;
cin>>n;
int n,cnt=0;;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
  1. 使用一个死循环,当无法继续\(\div2\)时,结束循环。
		bool pd=true;//①
for(int j=1;j<=n;j++)
{
if(a[j]%2!=0)
{
pd=false;
break;
}
}
if(pd==false)break;//②
if(pd)
{
cnt++;
for(int j=1;j<=n;j++)
a[j]/=2;
}

①判断能否被\(2\)整除使用的布尔型变量。

②循环的结束条件。

  1. 输出最终结果。
	cout<<cnt;

CODE

#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int main()
{
int n,cnt=0;;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;;i++)
{
bool pd=true;
for(int j=1;j<=n;j++)
{
if(a[j]%2!=0)
{
pd=false;
break;
}
}
if(pd==false)break;
if(pd)
{
cnt++;
for(int j=1;j<=n;j++)
a[j]/=2;
}
}
cout<<cnt;
return 0;
}

题解 AT3718 【[ABC081B] Shift only】的更多相关文章

  1. Codeforces Round #385 (Div. 2) A. Hongcow Learns the Cyclic Shift 水题

    A. Hongcow Learns the Cyclic Shift 题目连接: http://codeforces.com/contest/745/problem/A Description Hon ...

  2. ECJTUACM16 Winter vacation training #4 题解&源码

    A......................................................................................... 题目链接→Code ...

  3. 算法(第四版)C# 习题题解——2.2

    写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 查找更为方便的版本见:http ...

  4. 算法(第四版)C# 习题题解——2.1

    写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 这一节内容可能会用到的库文件有 ...

  5. AIM Tech Round 3 (Div. 1) A. Letters Cyclic Shift 贪心

    A. Letters Cyclic Shift 题目连接: http://www.codeforces.com/contest/708/problem/A Description You are gi ...

  6. leetcode & lintcode 题解

    刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度 ...

  7. 【codeforces】【比赛题解】#960 CF Round #474 (Div. 1 + Div. 2, combined)

    终于打了一场CF,不知道为什么我会去打00:05的CF比赛…… 不管怎么样,这次打的很好!拿到了Div. 2选手中的第一名,成功上紫! 以后还要再接再厉! [A]Check the string 题意 ...

  8. 算法(第四版)C#题解——2.1

    算法(第四版)C#题解——2.1   写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csh ...

  9. Codeforces Round #469 Div. 2题解

    A. Left-handers, Right-handers and Ambidexters time limit per test 1 second memory limit per test 25 ...

随机推荐

  1. Transformer 详解

    感谢:https://www.jianshu.com/p/04b6dd396d62 Transformer模型由<Attention is all your need>论文中提出,在seq ...

  2. 安装 Cacti 监控

    简介:                Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具.         Cacti是通过 snmpget来获取数据,使用 ...

  3. 珠峰-express

    ##### #### 中间件的作用 #### 自己写的Route方法 #### #### 中间件

  4. vs工程配置eslint检测环境

    vs工程打开一个js文件,会提示 "No ESLint configuration (e.g .eslintrc) found for file ......." 或 " ...

  5. css—动画(transform, transition, animation)

    transform 静态属性,一旦写进style里面,会立即显示作用,无任何变化过程.(类似于left, right, top, bottom这类属性) 主要用来做元素的变形 改变元素样式的属性主要有 ...

  6. openlayers6实现webgl点图层渲染效果(附源码下载)

    前言:openlayers6推出来的有一段时间,推出来的新特性见:https://github.com/openlayers/openlayers/releases/该版本的主要功能是能够组合具有不同 ...

  7. BOS只读状态修改

    update T_META_OBJECTTYPE set FSUPPLIERNAME ='PAEZ',FPACKAGEID =null

  8. Linux运维----03.制作trove-mysql5.7镜像

    安装mysql yum install http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm yum remove m ...

  9. Linux内核的LED设备驱动框架【转】

    /************************************************************************************ *本文为个人学习记录,如有错 ...

  10. 【HDU - 1029】Ignatius and the Princess IV (水题)

    Ignatius and the Princess IV  先搬中文 Descriptions:   给你n个数字,你需要找出出现至少(n+1)/2次的数字 现在需要你找出这个数字是多少? Input ...