zoukankan      html  css  js  c++  java
  • FZU-2268 Cutting Game(二进制使用)

     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;
    }
    

      

  • 相关阅读:
    AS3邮件
    JavaScript中this关键字使用方法详解
    AS3嵌入字体
    xp双击打不开jar包解决方案
    查询在表1表2中都存在,在表3中不存在的SQL(前提:表结构相同)
    这是否为复制Bug?求解!
    批处理添加允许弹出临时窗口站点
    SQL Server 合并IP
    C#学习笔记一(变量、属性、方法,构造函数)
    SQLServer事务的隔离级别
  • 原文地址:https://www.cnblogs.com/luowentao/p/9000638.html
Copyright © 2011-2022 走看看