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 ...
随机推荐
- Codeforces Round #313 (Div. 2) B. Gerald is into Art 水题
B. Gerald is into Art Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/560 ...
- Maven3.2创建webapp项目过程中问题以及解决方案
用maven组件来创建web项目,maven的好处一大堆,但是在创建项目的时候问题也很多,诸多不顺,网上找了很多资料,貌似都没能解决问题. 环境:jdk1.7.0_80,eclipse4.4,mave ...
- On Memory Leaks in Java and in Android.
from:http://chaosinmotion.com/blog/?p=696 Just because it's a garbage collected language doesn't mea ...
- 设置Delphi XE4默认界面样式
VCL BitMap Style Proceject Options->Application->Appearance 选择几个样式 使用代码设置 uses Vcl.Themes; ...
- HDU1013_Digital Roots【大数】【水题】
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- Maven 修改本地存储库位置--转
step1:默认会放在~/.m2/repository目录下 (“~”代表用户的目录,比如windows下一般都是C:\Documents and Settings\[你的用户名]\), step2: ...
- cocos2d-x lua 使用http(下载图片, POST JSON)
cocos2d-x lua 使用http(下载图片, POST JSON) version: cocos2d-x 3.6 1.使用http post json与服务器交互 require(" ...
- CoreDate的使用
勾选 xcode的 CoreDate会帮我们自动创建 CoreData 但是我们通常不那样使用,通常把 CoreDate 在单利类中创建, // // ZYDAO.h // StoryboardTes ...
- hibernate 插件安装
安装hibernate插件 1,help--install new software work with选择All Available Sites 搜索框输入hibernate 会出现所有hiber ...
- 自定义JPA之AttributeConverter
1. 执行类 public class BooleanConverter implements AttributeConverter<Boolean, Integer> { } 2. 属性 ...