FZU - 2062 - Suneast & Yayamao
先上题目:
Accept: 146 Submit: 319
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Yayamao is so cute that people loves it so much.
Everyone wants to buy Yayamao from Suneast (a business man who sells Yayamao).

Suneast is a strange business man. He sells Yayamao in a random price from 1, 2, 3, 4, 5…, n.
Suneast is also a lazy business man. He never looks for a change. But people can’t but Yayamao with a lower price, that say people must pay exact money for Yayamao.
Now, we want to know how many pieces of money people should bring with to buy a Yayamao with the exactly price.
Input
Output
Sample Input
Sample Output
Hint
In test case 1: people can bring 1 piece of money: 1
In test case 2: people can bring 2 pieces of money: (1, 1) or (1, 2)
In test case 3: people can bring 3 pieces of money: (1, 1, 3) or (1, 2, 2) ….
题意:给你一个数n,问你至少用多少个数,只用这些数就可以表示1~n的所有数。
比如5:1=1
2=1+1
3=1+2
4=2+2
5=1+1+3
当然可能还有很多的方法来表示1~5的数,不过一定需要三个。
其实我们可以这样分析,将这个数n化成二进制,假如它有l位,那么对于一个l位的二进制数,我们需要用l位二进制才可以将它表示出来,同时比它小的数,我们可以用不超过l位的数来保存表示它们,换言之,我们可以用2^0,2^1,2^2···2^k···这些数来表示从1~n的数,至于k等于多少,那就需要看n的二进制有多少位了。
这也是背包问题里面的多重背包的基础。
上代码:
#include <cstdio>
#include <cstring>
#define LL long long
#define MAX 2147483647
using namespace std; int main()
{
int n;
int tot;
//freopen("data.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
tot=;
while(n){
tot++;
n=n>>;
}
printf("%d\n",tot);
}
return ;
}
2062
FZU - 2062 - Suneast & Yayamao的更多相关文章
- 【二进制】FZU 2062 Suneast & Yayamao
题意:给出n,问最少需要多少个数字,这些数字能组成1~n的所有数: 分析:n=1; 1; 1个 n=2; 1,1; 2个 1 = 1; 2 = 1+1; n=3; 1,2; 2个 1 = 1; ...
- Problem 2062 Suneast & Yayamao 二进制(多重背包的理解基础)
Problem 2062 Suneast & Yayamao Accept: 143 Submit: 313T ...
- FZU Problem 2062 Suneast & Yayamao
http://acm.fzu.edu.cn/problem.php?pid=2062 题目大意: 给你一个数n,要求求出用多少个数字可以表示1~n的所有数. 思路: 分解为二进制. 对于一个数n,看它 ...
- FZU Problem 2062 Suneast & Yayamao
http://acm.fzu.edu.cn/problem.php?pid=2062 标题效果: 给你一个数n,要求求出用多少个数字能够表示1~n的全部数. 思路: 分解为二进制. 对于一个数n.看它 ...
- FZU 2240 Daxia & Suneast's problem
博弈,$SG$函数,规律,线段树. 这个问题套路很明显,先找求出$SG$函数值是多少,然后异或起来,如果是$0$就后手赢,否则先手赢.修改操作和区间查询的话可以用线段树维护一下区间异或和. 数据那么大 ...
- FZU 2137 奇异字符串 后缀树组+RMQ
题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...
- FZU 1914 单调队列
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...
- ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】
FZU 2105 Digits Count Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- [日常训练]yayamao的神题
Description $yayamao$是数学神犇,一天他在纸上计算起了$1/P$, 我们知道按照模拟除法可以得到准确解,例如$1/7=0.(142857),1/10=0.1(0)$.$yayama ...
随机推荐
- U4704 函数
U4704 函数 题目背景 设gcd(a,b)为a和b的最大公约数,xor(a,b)为a异或b的结果. 最大公约数 异或 题目描述 kkk总是把gcd写成xor.今天数学考试恰好出到了gcd(a,b) ...
- luogu3390 矩阵快速幂
矩阵A乘矩阵B是A的第i行向量乘以B的第j列向量的值放在结果矩阵的i行j列.因为矩阵乘法满足结合律,所以它可以与一般的快速幂算法同理使用.注意矩阵在乘的时候取模. #include <cstdi ...
- pass an instance of class to TestCase as parameter
use testcasesource instead https://stackoverflow.com/questions/4220943/how-to-pass-dynamic-objects-i ...
- C# 文件的一些基本操作(转)//用C#读写ini配置文件
C# 文件的一些基本操作 2009-07-19 来自:博客园 字体大小:[大 中 小] 摘要:介绍C#对文件的一些基本操作,读写等. using System;using System.IO;us ...
- 【POJ 3740】 Easy Finding
[题目链接] http://poj.org/problem?id=3740 [算法] Dancing Links算法解精确覆盖问题 详见这篇文章 : https://www.cnblogs.com/g ...
- QQ 临时会话+图标 HTML代码
啦啦啦 QQ会话的HTML代码 <a target="_blank" href="http://wpa.qq.com/msgrd?v=3& uin=2553 ...
- Cloudera Manager安装之利用parcels方式(在线或离线)安装单节点集群(包含最新稳定版本或指定版本的安装)(添加服务)(Ubuntu14.04)(四)
.. 欢迎大家,加入我的微信公众号:大数据躺过的坑 免费给分享 同时,大家可以关注我的个人博客: http://www.cnblogs.com/zlslch/ 和 http ...
- shiro英语
Security Manager安全管理人员 Tutorial 辅导的 transient 短暂的 Cipher 密码 Memory 记忆 Access 访问Handy Hint 方便提示separa ...
- 5.13redis的相关基础
二.Redis(NoSql) Redis是用C语言开发的一个开源的高性能键值对(key-value)数据库,官方提供测试数据,50个并发执行 100000个请求,读的速度是110000次/s,写的速 ...
- input表单(02)
01.表单的代码实现 <!DOCTYPE html> <html> <head> <title>世纪佳缘,你在我也在</title> < ...