FZU-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
3
Sample Output
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(二进制使用)的更多相关文章
- FZU - 2295 Human life:网络流-最大权闭合子图-二进制优化-第九届福建省大学生程序设计竞赛
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 http://acm.fzu.edu.cn/problem.php?pid=2295 htt ...
- 【二进制】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; ...
- UVA - 818 Cutting Chains(切断圆环链)(dfs + 二进制法枚举子集)
题意:有n个圆环(n<=15),已知已经扣在一起的圆环,现在需要打开尽量少的圆环,使所有圆环可以组成一条链. 分析:因为不知道要打开哪个环,如果列举所有的可能性,即枚举打开环的所有子集,最多才2 ...
- ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】
FZU 2105 Digits Count Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- FZU 1649 Prime number or not米勒拉宾大素数判定方法。
C - Prime number or not Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- FZU 1025 状压dp 摆砖块
云峰菌曾经提到过的黄老师过去讲课时的摆砖块 那时百度了一下题目 想了想并没有想好怎么dp 就扔了 这两天想补动态规划知识 就去FZU做专题 然后又碰到了 就认真的想并且去做了 dp思想都在代码注释里 ...
- FZU 2218 Simple String Problem(简单字符串问题)
Description 题目描述 Recently, you have found your interest in string theory. Here is an interesting que ...
- FZU 2105 Digits Count(按位维护线段树)
[题目链接] http://acm.fzu.edu.cn/problem.php?pid=2105 [题目大意] 给出一个序列,数字均小于16,为正数,每次区间操作可以使得 1. [l,r]区间and ...
- FZU Super A^B mod C(欧拉函数降幂)
Problem 1759 Super A^B mod C Accept: 878 Submit: 2870 Time Limit: 1000 mSec Memory Limit : 327 ...
随机推荐
- 《Cracking the Coding Interview》——第1章:数组和字符串——题目8
2014-03-18 02:12 题目:判断一个字符串是否由另一个字符串循环移位而成. 解法:首先长度必须相等.然后将第一个串连拼两次,判断第二个串是否在这个连接串中. 代码: // 1.8 Assu ...
- js限制文本框只能输入特定字符
限制只能输入数字 // ---------------------------------------------------------------------- // <summary> ...
- 【Pascal's Triangle II 】cpp
题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [ ...
- Python 3基础教程11-如何利用pip命令安装包和模块
本文介绍如何利用pip命令安装Python相关的包和模块.在Python中有些方法或者模块是自带的功能,也叫(build-in),内构函数,实际使用,可能内构函数或者模块不能完成我们的任务,我们就需要 ...
- 一个初学者的辛酸路程-前端js
内容回顾: 1.CSS的基本概念: 层叠样式表. 2.CSS的三种书写方式 ① 行内样式 <div style="color: red;">sdfdsf</div ...
- iframe 如何让它展现内容自适应高度
引用: <iframe id="ifm1" runat="server" src="/comment/page1?id=@productId&q ...
- (原)Unreal源码搬山-动画篇 自定义动画节点(一)
@author:黑袍小道 太忙了,来更新下,嘿嘿 前言: 本文是接着上文 Unreal搬山之动画模块_Unreal动画流程和框架,进行简单入门如何自定义动画图标的AnimNode. 正文: 一.Ani ...
- 替换Fragment 报错 The specified child already has a parent. You must call removeView() on the child's parent first.
在将一个fragment替换到一个frameLayout的时候报错: code: transaction.replace(R.id.fragment_container, fragment2); 错误 ...
- maven中mapper.xml不发布的问题
在自定义的包中定义了mapper.xml然后利用mybatis的扫描包形式来动态创建mapper 开启工程报错: 说无效的绑定 原因: 发布的war中,工程包中的mapper根本就没有出现在class ...
- 201621123034 《Java程序设计》第12周学习总结
作业12-流与文件 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车 ...