Problem 2268 Cutting Game

Accept: 254    Submit: 605
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

Fat brother and Maze are playing a kind of special (hentai) game with a piece of gold of length N where N is an integer. Although, Fat Brother and Maze can buy almost everything in this world (except love) with this gold, but they still think that is not convenient enough. Just like if they would like to buy the moon with M lengths of the gold, the man who sold the moon need to pay back Fat Brother and Maze N-M lengths of the gold, they hope that they could buy everything they can afford without any change. So they decide to cut this gold into pieces. Now Fat Brother and Maze would like to know the number of the pieces they need to cut in order to make them fulfill the requirement. The number of the gold pieces should be as small as possible. The length of each piece of the gold should be an integer after cutting.

 Input

The first line of the data is an integer T (1 <= T <= 100), which is the number of the text cases.

Then T cases follow, each case contains an integer N (1 <= N <= 10^9) indicated the length of the gold.

 Output

For each case, output the case number first, and then output the number of the gold pieces they need to cut.

 Sample Input

1
3

 Sample Output

Case 1: 2

 Hint

In the first case, the gold can be cut into 2 pieces with length 1 and 2 in order to buy everything they can afford without change.

 Source

第七届福建省大学生程序设计竞赛-重现赛(感谢承办方闽江学院)

 
题意:

给你一个数,然后让你切割,问的是最少切割几个,就可以组成所有的数

这是一个规律,实际上就是求这个数的二进制有几位数

代码:

#include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
using namespace std;
#define INF 0x3f3f3f3f
int mapp[150][150];
int flag[150][150];
int sum; int main()
{
std::ios::sync_with_stdio(false);
int t,n,o=0;
cin>>t;
while(t--){
o++;
cin>>n;
int k=1,cut=0;
while(n>0)
{
n-=k;
cut++;
k=k*2;
}
cout<<"Case "<<o<<": "<<cut<<endl;
}
return 0;
}

  

FZU-2268 Cutting Game(二进制使用)的更多相关文章

  1. FZU - 2295 Human life:网络流-最大权闭合子图-二进制优化-第九届福建省大学生程序设计竞赛

    目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 http://acm.fzu.edu.cn/problem.php?pid=2295 htt ...

  2. 【二进制】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; ...

  3. UVA - 818 Cutting Chains(切断圆环链)(dfs + 二进制法枚举子集)

    题意:有n个圆环(n<=15),已知已经扣在一起的圆环,现在需要打开尽量少的圆环,使所有圆环可以组成一条链. 分析:因为不知道要打开哪个环,如果列举所有的可能性,即枚举打开环的所有子集,最多才2 ...

  4. ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】

     FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  5. FZU 1649 Prime number or not米勒拉宾大素数判定方法。

    C - Prime number or not Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  6. FZU 1025 状压dp 摆砖块

    云峰菌曾经提到过的黄老师过去讲课时的摆砖块 那时百度了一下题目 想了想并没有想好怎么dp 就扔了 这两天想补动态规划知识 就去FZU做专题 然后又碰到了 就认真的想并且去做了 dp思想都在代码注释里 ...

  7. FZU 2218 Simple String Problem(简单字符串问题)

    Description 题目描述 Recently, you have found your interest in string theory. Here is an interesting que ...

  8. FZU 2105 Digits Count(按位维护线段树)

    [题目链接] http://acm.fzu.edu.cn/problem.php?pid=2105 [题目大意] 给出一个序列,数字均小于16,为正数,每次区间操作可以使得 1. [l,r]区间and ...

  9. FZU Super A^B mod C(欧拉函数降幂)

    Problem 1759 Super A^B mod C Accept: 878    Submit: 2870 Time Limit: 1000 mSec    Memory Limit : 327 ...

随机推荐

  1. Django笔记 —— 模板

    最近在学习Django,打算玩玩网页后台方面的东西,因为一直很好奇但却没怎么接触过.Django对我来说是一个全新的内容,思路想来也是全新的,或许并不能写得很明白,所以大家就凑合着看吧- 本篇笔记(其 ...

  2. 使用java去对比2个带数学公式的字符串

    首先大家看到这个题目,可能会不屑一顾,呵呵,是的,起初我也认为这是个很简单的任务,当任务拿到手里后,经过我作为程序员来讲已经磨炼的无比通透的大脑来讲发现这其实是个坑. 故事的起因是这样的,想开发一款给 ...

  3. 利用socket.io构建一个聊天室

    利用socket.io来构建一个聊天室,输入自己的id和消息,所有的访问用户都可以看到,类似于群聊. socket.io 这里只用来做一个简单的聊天室,官网也有例子,很容易就做出来了.其实主要用的东西 ...

  4. Mysql忘记root密码怎么办?(已解决)

    为了写这篇文档,假装一下忘记密码!!!! 首先我数据库是正常的,可以使用. root@localhost:~# mysql -uroot -p mysql> mysql> show dat ...

  5. super和final关键字

    一.super关键字 super关键字的使用 JAVA类中使用super来引用父类的属性或者方法,用this来引用当前对象,主要用法: 1.子类的构造函数默认第一行会默认调用父类的无参数构造函数 2. ...

  6. 第二阶段团队冲刺-three

    昨天: 修复博客作业查询功能. 今天: 绘制logo. 遇到的问题: 无.

  7. ActiveX 控件和 Web 浏览器加载项

    百度ActiveX的概念. 如何从零开始写一个 Chrome 扩展 360极速浏览器应用开发平台.

  8. 哈夫曼树(C++优先队列的使用)

       给定n个权值作为n个叶子结点,构造一棵二叉树,若带权路径长度达到最小,称为哈夫曼树(Huffman Tree).哈夫曼树是带权路径长度最短的树,权值较大的结点离根较近.    构造 假设有n个权 ...

  9. vb如何将数据库中某个字段显示在一个文本框

    Dim mrc As ADODB.Recordset Private Sub cmdQuery_Click() Dim txtSQL As String Dim MsgText As String t ...

  10. IPv6的一些特殊地址

    IPv6的一些特殊地址   2008年7月3日第二次修正! 昨天是修正了地址部分,本想发上来的,没来得及.今天修正了NDP协议,接下来会是路由和转换部分. 总结一下各协议的精华:OSPF在于LSA,B ...