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. 程序员必备PC维修法(硬件篇)

    自检自修不是万能,但不会自检自修却万万不能.程序员修电脑还是有必要的. 情景:通电情况下,电脑主机无法启动,所有主机内部硬件无反应. 原因:1.CPU.主板.电源积尘.(出现率30%) 2.CPU.主 ...

  2. 恢复误删除表黑科技之relay log大法

      Preface       In my previous blogs,I've demonstrated several mothods of how to rescue a dropped ta ...

  3. katalon系列二:selenium IDE的替代者——Katalon Recorder

    Katalon Recorder是和selenium IDE一样的一个浏览器插件,可以录制web上的操作并回放,但我个人感觉Katalon Recorder更好用.大家可以直接在chrome商店下载安 ...

  4. Python 3基础教程14-在文件尾部更新内容

    本文介绍在一个已经存在的文件尾部添加内容,还是用到write方法. 这里exampleFile.txt是前面文件创建的文件,里面有两行文字.

  5. [译]16-spring基于注解的配置元数据

    从spring2.5起spring框架开始支持java注解的配置元数据.所以除了使用xml配置文件来描述bean的装配之外,你还 可以使用基于java注解的配置元数据来完成同样的功能. spring框 ...

  6. CMake Tutorial & Example

    Tutorial CMakeLists用于告诉CMake我们要对这个目录下的文件做什么事情 cmake 的特点主要有: 1,开放源代码,使用类 BSD 许可发布.http://cmake.org/HT ...

  7. 聊聊、Git 常用命令

    创建本地仓库git initgit add .git commit -m "xxxxx"git remote add origin http://git.xxx.com/xxx.g ...

  8. 爬虫:Scrapy13 - 发送 email

    虽然 Python 通过 smtplib 库使得发送 email 变得非常简单,Scrapy 仍然提供了自己的实现.该功能十分易用,同时由于采用了 Twisted 非阻塞式(non-blocking) ...

  9. Java Web Action DAO Service层次理解

    参考来源:http://blog.csdn.net/inter_peng/article/details/41021727 1. Action/Service/DAO简介: Action是管理业务(S ...

  10. 01、dos命令行的常用命令

    cd 进入指定目录cd..  返回上一级目录cd\   退回盘符根目录dir        列出当前目录下的文件以及文件夹md       创建目录rd 删除目录del   删除文件cls       ...