UVa11384
题意:给定正整数n,求把1,2,……,n中所有书都变成0的最少操作次数,每次操作可从序列中选择一个或多个整数,同时减去一个相同的正整数。
分析:如1,2,3,4,5,6,
第一步将4,5,6同时减4,则变成了1,2,3,0,1,2
情况与1,2,3相同,由此可知f(n) = f(n / 2) + 1
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<algorithm>
#include<set>
#include<stack>
#include<list>
#include<map>
#include<queue>
#include<deque>
#include<vector>
#include<cctype>
using namespace std;
const int MAXN = + ;
const int MAXT = + ;
const int INF = 0x7f7f7f7f;
const double EPS = 1e-;
const double PI = acos(-1.0);
typedef long long ll;
typedef unsigned long long llu;
int f(int n)
{
return n == ? : f(n / ) + ;
}
int main()
{
int n;
while(scanf("%d", &n) != EOF)
printf("%d\n", f(n));
return ;
}
UVa11384的更多相关文章
- Uva11384 Help is needed for Dexter
Dexter is tired of Dee Dee. So he decided to keep Dee Dee busy in a game. The game he planned for he ...
- UVA11384正整数序列(把123..变成0的最小步数)
题意: 给定一个正整数n,你的任务是最少的操作次数把序列1 2 3 4 5...n中所有的数字都变成0,每次操作可以从序列中选择一个活多个整数,同时减去一个相同的正整数,比如 1 2 3可以 ...
- Uva 11384 正整数序列
题目链接:https://vjudge.net/problem/UVA-11384 题意:给定正整数 n,用最少的操作把序列 1,2,,,n 全部变成 0: 操作是:每次可以从序列中选择一个或者多个, ...
- UVA 11384 Help is needed for Dexter(递归)
题目链接:https://vjudge.net/problem/UVA-11384 这道题要分析得透: 如果我们手模的话,会发现:如果先将大于$\frac{n}{2}$的数都减去$\frac{n}{2 ...
随机推荐
- delphi 中DLL的建立
Dll的创建与调用 File ->New->Other->Dll Wizard DLL的创建 //可以将本代码复制粘贴到项目中 library Project1; uses S ...
- [AngularJS] ngModelController render function
ModelValue and ViewValue: $viewValue: Actual string value in the view. $modelValue: The value in the ...
- LINUX 内核导论
http://blog.csdn.net/ljy1988123/article/category/1490573/2
- Cobra —— 可视化Python虚拟机 and 图解python
http://blog.csdn.net/balabalamerobert http://blog.csdn.net/efeics/article/category/1486515 图解python ...
- UNIX基础知识之程序和进程
一.程序 程序(program)是存放在磁盘上.处于某个目录中的一个可执行文件.使用6个exec函数中的一个由内核将程序读入存储器,并使其执行. 二.进程和进程ID 程序的执行实例被称为进程(proc ...
- struts2简单示例
今天写一个struts2的例子,目的是为了让大家明白struts2的基本流程,其实框架没有大家想象的那么难,说白了struts2的本质就是一个大的Servlet,即原本需要提交到Servlet处理的部 ...
- Java SE ---关系运算符
java里的关系运算符有这么几种:大于(>).小于(<).等于(==).不等于(!=).大于等于(>=).小于等于(<=), 关系运算的结果是个boolean值,关系式成立为t ...
- 利用传感器(sensor)实现微信摇一摇动画
所需要的权限: <uses-permission android:name="android.permission.VIBRATE"></uses-permiss ...
- sql 自定义函数--十进制转二进制
随笔记忆: if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DECTOBIN]') and xtype in ...
- CF Polycarpus' Dice (数学)
Polycarpus' Dice time limit per test 1 second memory limit per test 256 megabytes input standard inp ...