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 ...
随机推荐
- linux-ntp-10
Unix/linux类:ntp.aliyun.com,ntp1-7.aliyun.com windows类: time.pool.aliyun.com s1a.time.edu.cn 北京邮电大学 s ...
- 这个 'ip' 竟然把我搞蒙圈了……
1.查看redis连接配置(某项目) <bean id="redisCacheServer" class="com.spring.cache.RedisCacheS ...
- Selenium 多表单(frame/iframe)切换
frame标签有frameset.frame.iframe三种,frameset跟其他普通标签没有区别,不会影响到正常的定位,而frame与iframe需要切换进去才能定位到其中的元素 比如下面这个网 ...
- Codeforces Round #403---C题(DFS,树)
C. Andryusha and Colored Balloons time limit per test 2 seconds memory limit per test 256 megabytes ...
- centos-系统删除多余网卡的方法
一.删除系统中中多余的ifcfg-eth0.bak Centos系统更改网卡或网卡MAC地址后会出现个eth0.bak配置备份文件解决方法:/etc/sysconfig/networking/devi ...
- DVWA--XSS(stored)
XSS 0X01 1.简介 跨站脚本(cross site script)为了避免与样式css混淆,所以简称为XSS. XSS是一种经常出现在web应用中的计算机安全漏洞,也是web中最主流的攻击方式 ...
- vue树形菜单
vue树形菜单 由于项目原因,没有使用ui框架上的树形菜单,所以自己动手并参考大佬的代码写了一个树形菜单的组件,话不多说,直接上代码.html代码js代码直接调用api 把请求到的数据直接赋值给per ...
- Vue学习(一) :入门案例
1. 开始前的准备 IDE:VSCode(推荐)或者Sublime Text 前导技术:JavaScript中级 2. 官方提供的product例程 product.html页面代码: <div ...
- 屏蔽ffmpeg命令的所有提示
有时候需要隐蔽的执行ffmpeg不希望输出任何日志,提示.这个时候只需要多添加这个参数即可 -loglevel quiet
- 修改win10 capslock键成esc键 vim
桌面编辑一个文件CapsLock2Esc.reg Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentCont ...