题解 AT3718 【[ABC081B] Shift only】
分析
直接暴力。
我们可以根据题意进行模拟,使用二重循环即可。
代码讲解
- 定义变量\(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];
- 使用一个死循环,当无法继续\(\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\)整除使用的布尔型变量。
②循环的结束条件。
- 输出最终结果。
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】的更多相关文章
- 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 ...
- ECJTUACM16 Winter vacation training #4 题解&源码
A......................................................................................... 题目链接→Code ...
- 算法(第四版)C# 习题题解——2.2
写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 查找更为方便的版本见:http ...
- 算法(第四版)C# 习题题解——2.1
写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 这一节内容可能会用到的库文件有 ...
- 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 ...
- leetcode & lintcode 题解
刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度 ...
- 【codeforces】【比赛题解】#960 CF Round #474 (Div. 1 + Div. 2, combined)
终于打了一场CF,不知道为什么我会去打00:05的CF比赛…… 不管怎么样,这次打的很好!拿到了Div. 2选手中的第一名,成功上紫! 以后还要再接再厉! [A]Check the string 题意 ...
- 算法(第四版)C#题解——2.1
算法(第四版)C#题解——2.1 写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csh ...
- Codeforces Round #469 Div. 2题解
A. Left-handers, Right-handers and Ambidexters time limit per test 1 second memory limit per test 25 ...
随机推荐
- MySQL数据库的备份、还原、迁移
一.单库备份与还原 1.远程连接MySQL数据库 D:\mysql-5.7.14-winx64\bin>mysql -h192.168.2.201 -uroot -pcnbi2018 参数说明: ...
- HTTP 1.1状态代码及其含义
HTTP 1.1状态代码及其含义 100 Continue 初始的请求已经接受,客户应当继续发送请求的其余部分.(HTTP 1.1新) 101 Switching Protocols 服务器将 ...
- Spark SQL 之自定义删除外部表
前言 Spark SQL 在删除外部表时,本不能删除外部表的数据的.本篇文章主要介绍如何修改Spark SQL 源码实现在删除外部表的时候,可以带额外选项来删除外部表的数据. 本文的环境是我一直使用的 ...
- JVM垃圾回收——GC
一.JVM内存分配与回收 下图为堆内存结构图(注意:元数据区(MetaData )实际上不属于堆): 1.对象优先在Eden区分配 大多数情况下,对象在新生代中Eden区分配.当Eden区没有足够空间 ...
- ArcGIS Server、SDE许可更新
环境:windows server2008,ArcGIS10.1系列. 一.更新arcgis server许可 选择许可文件进行导入即可.注意最好从开始程序中找到并打开软件授权窗口.直接双击运行ecp ...
- React Native运行出现Could not find "iPhone X" simulator
打开项目文件夹下 node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js 查找 if (!version.startsW ...
- AndroidStudio修改默认C盘配置文件夹(.android.gradle.AndroidStudio)以及修改后避免踩的坑
场景 AndroidStudio下载安装教程(图文教程): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103672471 在上 ...
- MySQL - SQL语句优化方法
1.使用 show status 了解各种 SQL 的执行频率 mysql> show status like 'Com%'; 该命令可以查询 sql 命令的执行次数. 2.定位执行效率较低的 ...
- CSGO控制台命令
转帖: 按下“~”即可开启 使用时先输入参数名 然后按下SPACE空出一格 再输入设定值即可 一般玩家进入游戏都只能用到Client(玩家用参数) 不过...如果你是开LAN GAME的人 就能进阶到 ...
- 第一天,初学Markdown
Markdown学习 二级标题 三级标题 字体 hello,world hello,world hello,world hello,world 引用 飞冲 分割线 图片 超链接 跳转到安徽科技学院 列 ...