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 ...
随机推荐
- MySQL错误日志显示(Got an error reading communication packets)的问题
错误显示: 2019-05-28T12:54:08.267934+08:00 820396 [Note] Aborted connection 820396 to db: 'Databaseplatf ...
- linux-awk-3
awk 基础语法 Awk –Fs '/pattern/ {action}' input-file (或者) Awk –Fs '{action}' input-file -F 为字段分界符.如果不指定, ...
- 树状数组(Binary Indexed Tree)
树状数组(Binary Indexed Tree,BIT) 是能够完成下述操作的数据结构. 给一个初始值全为 0 的数列 a1, a2, ..., an (1)给定 i,计算 a1+a2+...+ai ...
- FastDfs单机版搭建
详细的最新版fastdfs单机版搭建 前言 目前项目是tomcat单机部署的,图片.视频也是上传到tomcat目录下,关键是此项目的主要内容还就是针对图片.视频的,这让我非常担忧:文件服务器的应用是必 ...
- 【canvas学习笔记四】绘制文字
本节我们来学习如何绘制文字. 绘制文字有两个主要的方法: fillText(text, x, y [, maxWidth]) 在x, y位置填充文字text,有一个可选参数maxWidth设置最大绘制 ...
- 响应式布局@media screen and ( max-width: 像素值 ) {}
设计思路很简单,首先先定义在标准浏览器下的固定宽度(假如标准浏览器的分辨率为1024px,那么我们设置宽为980px),然后用Media Query来监测浏览器的尺寸变化,当浏览器的分辨率小于1024 ...
- (转)搭建自己的Nuget服务器
转:https://www.cnblogs.com/knowledgesea/p/5500954.html 序言 你们公司有没有好多项目,有没有好多类库,你们的类库是在tfs中管理,还是svn或者gi ...
- VASP学习笔记--简单的VASP运行实例:CrI3做非磁的优化
一.总体思路 1)写入INCAR: 2)写入POSCAR,就是坐标文件: 3)写入KPOINTS文件,就是K点的选择: 4)写入POTCAR,写入POTCAR(找到势文件,然后按照POSCAR中的元素 ...
- flask环境布署--废弃不用,只留作备份
[前置条件] 创建1个flask-demo,生成requirement.txt文件(下载好gunicorn),上传至git.创建demo参照:创建一个flask api-demo(响应体显示中文) g ...
- 阶段3 1.Mybatis_09.Mybatis的多表操作_2 完成account表的建立及实现单表查询
mybatis中的多表查询: 示例:用户和账户 一个用户可以有多个账户 一个账户只能属于一个用户(多个账户也可以属于同一个用户) ...