题解 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 ...
随机推荐
- 「Flink」使用Java lambda表达式实现Flink WordCount
本篇我们将使用Java语言来实现Flink的单词统计. 代码开发 环境准备 导入Flink 1.9 pom依赖 <dependencies> <dependency> < ...
- 加速github访问速度
打开https://www.ipaddress.com/ 查询以下三个链接的DNS解析地址 github.com assets-cdn.github.com github.global.ssl.fas ...
- C# 调用WCF服务的两种方法
项目简介 之前领导布置一个做单点登录的功能给我,实际上就是医院想做一个统一的平台来实现在这个统一的平台登录后不需要在His.Emr.Lis等系统一个个登录,直接可以登录到对应的系统,然后进行相应的操作 ...
- C#里面低消耗获取当前时间的思路
Linux下有vsyscall来优化一些例如time(NULL), gettimeofday这种调用的消耗; 但是Windows下, 没有类似的东西, 但是思路还是有的 1. 程序启动的时候, 获取一 ...
- 树莓派搭载CentOS7系统初始配置
系统属性: 树莓派型号:3b SD:32GB 系统:CentOS-Userland-7-armv7hl-RaspberryPI-Minimal-1908-sda.raw 开机配置: 连接树莓派: 配件 ...
- Galactic Collegiate Programming Contest Gym - 101572G 模拟
#include<bits/stdc++.h> using namespace std; int n,m; struct node { int id; int slove; int pen ...
- linux 下生成 ssh 公私钥
生成命令 ssh-keygen -t rsa -C "763941715@qq.com" 密匙目录 cd ~/.ssh 公钥 id_rsa.pub 私钥 id_rsa
- 转载 CXF动态调用webservice
/** * * @param wsdlUrl wsdl的地址:http://localhost:8001/demo/HelloServiceDemoUrl?wsdl * @param methodNa ...
- Quartz.NET - 教程 5: 简单触发器
译者注: 目录在这 Quartz.NET 3.x 教程 原文在这 Lesson 5: SimpleTrigger 如果你需要在特定的时间点执行一次作业, 或者在特定的时间点执行一次作业, 然后在特定的 ...
- 剑指offer-面试题56_2-数组中唯一只出现一次的数字-位运算
/* 题目: 数组中除一个数字只出现一次外,其余数字都出现3次. */ /* 思路: 位运算. */ #include<iostream> #include<cstring> ...