Break Number --AtCoder
题目描述
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
6 can be divided by 2 once: 6 -> 3.
8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
3 can be divided by 2 zero times.
Constraints
1≤N≤100
输入
N
输出
样例输入
7
样例输出
4
分析:这题之前理解错题意WA了好几发(辣鸡队友瞎说题意),其实就是找n以内的最大2的平方数。
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int n,ans,acnt;
void init(){
cin>>n;
}
void solve(){
while(n){
++ans;
n>>=;
}
cout<<(<<(ans-))<<endl;
}
int main() {
init();
solve();
return ;
}
Break Number --AtCoder的更多相关文章
- AtCoder Beginner Contest 068 ABCD题
A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...
- AtCoder Beginner Contest 068
A - ABCxxx 题意: 给出n,输出“ABCn”就可以了,纯水题. B - Break Number 题意: 给出n,找出从1到n的闭区间内能够被2整除最多次的数. 思路: 直接模拟. 代码: ...
- 头条面试题:判断一个数是否是happy number(每一位的平方和最终为1)
朋友面试头条二轮了,一轮的题目请看这一篇:头条面试题:求用户在线峰值和持续时间 这次的面试题目是:判断一个数是否是happy number(每一位的平方和最终为1) 知道题目首先要理解题目.所谓hap ...
- 初识Java-分数录入系统
package classTest; import java.util.Scanner; public class scoreArrangement { /** * 选择界面(main) */ p ...
- Linux命令总结【待续】
1.打包: tar -czf small.tar.gz small(目录名) ;压缩并打包目录 2.解包: tar zxvf 文件名 date -s 2015 2 12 修改时间 cp name ...
- ViewPager+Fragment再探:和TAB滑动条一起三者结合
Fragment前篇: <Android Fragment初探:静态Fragment组成Activity> ViewPager前篇: <Android ViewPager初探:让页面 ...
- Android ViewPager再探:增加滑动指示条
上一篇:<Android ViewPager初探:让页面滑动起来> ViewPager只是左右滑动有些丑,也不知道当前位于第几页面. 可以在上方加入滑动指示条,来确定当前位置. 只需要修改 ...
- Python: PDB命令
1. where(w) 找出当前代码运行位置 2. list(l) 显示当前代码的部分上下文 3. list <line number> 显示指定行的上下文 4. list <lin ...
- Ultra-QuickSort
Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 44489 Accepted: 16176 ...
随机推荐
- Linux命令之----tree
命令简介 tree命令的中文意思为“树”,功能是以树形结构列出指定目录下的所有内容,包括所有文件.子目录及子目录里的目录和文件. 命令格式 tree [option] [directory]tree ...
- Linux档案与文件系统的压缩与打包
总结: 压缩指令为透过一些运算方法去将原本的档案进行压缩,以减少档案所占用的磁盘容量.压缩前与压缩后的档案所占用的磁盘容量比值,就可以被称为是“压缩比” 压缩的好处是可以减少磁盘容量的浪费,在www网 ...
- js基础之javascript函数定义及种类-普通涵数-自执行函数-匿名函数
普通函数 1.不带参数 function fucname(){ alert("hello"); } funcname() 2.带参数 function funcname(arg){ ...
- bash shell命令与监测的那点事(二)
bash shell命令与监测的那点事之top 上次我们说到了ps命令,ps命令虽然在收集运行在系统上的进程信息很有用,但是也有不足之处,ps命令只能显示某个特定时间点的信息,如果你想观察频繁换进换出 ...
- jenkins忘记管理员登陆密码
配置文件的路径在.../jenkins/config.xml (线上路径是/usr/local/tomcat7/webapps/jenkins/config.xml) 修复办法:千万注意:修复前一定要 ...
- 使用hibernate建立mysql连接以及生成映射类和配置文件*.cfg.xml
建立数据库连接 找到window—open perspective—myeclipse database explore空白出右键new注意 driver template 和driver class ...
- zookeeper 集群
集群步骤: 1.安装zookeeper 2.修改zookeeper配置文件 3.创建myid文件 安装zookeeper:查看安装步骤 修改zookeeper配置文件:在zoo.cfg中添加配置 se ...
- HDU3232 Crossing Rivers 数学期望问题
Crossing Rivers ...
- Mybatis通过接口的方式实现增删改查
导入jar包 [mybatis] [oracle] 生成数据库 1.添加Mybatis的配置文件mybatis-config.xml 在src目录下创建一个mybatis-config.xml文件,如 ...
- 解决云服务器ECS,windows server 2012不能安装SQL Server 2012,不能安装.NET Fromework 3.5
在云服务器上安装SQL Server 2012 时出现“启用windows功能NetFx3时出错”的问题:NetFx3指的是.NET Framework 3.5,SQL Server 2012数据库系 ...