HNUSTOJ 1604:Operations
1604: Operations
时间限制: 2 Sec 内存限制: 128 MB
提交: 313 解决: 97
[提交][状态][讨论版]
题目描述
You can perform the following operations.
- i = i+1;
- i = i-1;
- i = i/2 if i is even
The number i is integer. Find the minimal number of operations to get 0.
输入
Each line contains an N, 1 ≤ N ≤ 2000000。 Process to end of file.
输出
For each case, print one line containing an integer which is the minimal number of operations from N to 0.
样例输入
41559
样例输出
369
提示
来源
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include<iostream>#include<cstring>#include<cstdio>using namespace std;const int N = 2000000+5;int a[N];void Init(){ memset(a,0,sizeof(a)); for(int i=2;i<N;i+=2){ if(i%2==0){ int tmp = i; while(true){ tmp/=2; if(tmp%2) break; } a[i] = tmp; } }}int main(){ Init(); int n; while(scanf("%d",&n)==1){ int cnt = 0; while(true){ if(n==1){cnt++;break;} if(n%2==0){n/=2;cnt++;} else{ n = a[n-1]>a[n+1]?n+1:n-1; cnt++; } } printf("%d\n",cnt); } return 0;} |
HNUSTOJ 1604:Operations的更多相关文章
- backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized.
昨天在检查YourSQLDba备份时,发现有台数据库做备份时出现了下面错误信息,如下所示: <Exec> <ctx>yMaint.ShrinkLog</ctx> ...
- HDU 5938 Four Operations(四则运算)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- ios基础篇(二十九)—— 多线程(Thread、Cocoa operations和GCD)
一.进程与线程 1.进程 进程是指在系统中正在运行的一个应用程序,每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内: 如果我们把CPU比作一个工厂,那么进程就好比工厂的车间,一个工厂有 ...
- OpenCascade Modeling Algorithms Boolean Operations
Modeling Algorithms Boolean Operations of Opencascade eryar@163.com 布尔操作(Boolean Operations)是通过两个形状( ...
- A.Kaw矩阵代数初步学习笔记 4. Unary Matrix Operations
“矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...
- A.Kaw矩阵代数初步学习笔记 3. Binary Matrix Operations
“矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...
- mouse scrollings and zooming operations in linux & windows are opposite
mouse scrollings and zooming operations in linux & windows are opposite. windows中, 鼠标滚动的方向是: 查看页 ...
- MongoDB—— 写操作 Core MongoDB Operations (CRUD)
MongoDB使用BSON文件存储在collection中,本文主要介绍MongoDB中的写操作和优化策略. 主要有三种写操作: Create Update ...
- MongoDB—— 读操作 Core MongoDB Operations (CRUD)
本文主要介绍内容:从MongoDB中请求数据的不同的方法 Note:All of the examples in this document use the mongo shell interface ...
随机推荐
- py从入门到实践 第四章
4.1 遍立列表 ~= shell 数组————————————————————————————————————————————thrink = ['link','path','pwd']for i ...
- luoguP1255 数楼梯 x
P1255 数楼梯 题目描述 楼梯有N阶,上楼可以一步上一阶,也可以一步上二阶. 编一个程序,计算共有多少种不同的走法. 输入输出格式 输入格式: 一个数字,楼梯数. 输出格式: 走的方式几种. 输入 ...
- PHP 发邮件《转》
导读:PHP自带的mail()函数,是php内置发邮件的函数,该函数虽然简单,但是要想真正可以发邮件得有很复杂的配置.不适合新手,以及项目实际的应用的开发. php的mail()函数复杂配置,使得直接 ...
- Card Game Cheater
Card Game Cheater Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- [spring jpa] 解决SimpleJpaRepository的多数据源配置问题
前言 前段时间使用spring jpa做了一个项目,由于涉及到了多个数据库,因此需要进行多数据源的配置.网上找了很多的资料,尝试着配置,都以失败告终.之后通过断点最终完成了多数据源的配置.这篇博客主要 ...
- JavaScript Map 和 Object 的区别
不同点 Key filed 在 Object 中, key 必须是简单数据类型(整数,字符串或者是 symbol),而在 Map 中则可以是 JavaScript 支持的所有数据类型,也就是说可以用一 ...
- html初体验#1
html的一些自见解 html 5 自带语义化,就是让标签带上感情色彩,方便人或浏览器区分 <b></b>与<strong></strong>的区别 & ...
- Nodejs搭建音视频通信-信令服务器 总结
1.安装nodejs node-v10.16.3-x64.msi 2.安装配置环境变量 这里的环境配置主要配置的是npm安装的全局模块所在的路径,以及缓存cache的路径,之所以要配置,是因为以后在 ...
- mysql中查看ef或efcore生成的sql语句
http://www.solves.com.cn/it/sjk/MYSQL/2019-07-01/1336.html 涉及命令 1.开启general log模式 MySQL>set globa ...
- C++引用与传参
# include <iostream> using namespace std; void Swap(int *pa, int *pb) { int t = *pa; *pa = *pb ...