zoukankan      html  css  js  c++  java
  • MacaW Baby Learns Computer

    A - Macaw Baby Learns Computer
    Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
    Submit Status

    Description

    Download as PDF

    Problem F

    MacaW Baby Learns Computer

    The newborn Macaw baby is learning computer now. But as the Macaw dad cannot afford much so he has bought a computer that supports only floating-point data type (No support for integers). But as birds don’t give exams (no CGPA calculation), don’t calculate probability (Ignoring problem-setter birds) and don’t intentionally share food so they rarely do floating-point calculations. Luckily, floating-point numbers can hold many integer values perfectly. Now your job is to convince the Macaw dad how good a floating-point number is in holding integer values. For this problem floating-point numbers (Similar to real world no doubt) are stored in the following way:

    Suppose there is a binary number 10112, then to store it in computer as a floating-point number, it is divided into two parts,(a) mantissa(b) exponent. If value of mantissa part is mv, then . So it is stored as, 0.1011*24 (Assuming there is 4 bits of storage for mantissa). In other words the four bits allocated for mantissa contains 1011 and the exponent part contains the value 4 (In binary of course). As the most significant bit of mantissa is always 1 so it is not even stored at all. So for storing 10112 the mantissa part contains 011 (Ignoring the most siginificantbit 1) and the exponent part contains 100 (Binary equivalent of 4). Given the number of bits allocated for mantissa and exponent, your job is to find out how many different positive integer values can this floating-point number represent. In real life in floating-point number a bit is used for sign of number and another bit is used for sign of exponent. Those two bits are not needed for this problem (As negative integers are not counted and negative exponent never makes a positive integer value)

     

     

    Input


    The input file contains at most1000 lines of input. Each line contains two integers m (1 ≤ m ≤ 60) and e (1 ≤ e ≤ 60) which denotes the number of bits allocated for mantissa and exponent respectively.

    A line containing two zeroes terminates the input. This line should not be processed.

    Output


    For each test case produce one line of output. This line contains an integer which denotes how many different positive integer values this floating-point number can represent. You can assume that the input values will be such that this integer will not exceed 9*1018.


    Sample Input

    Output for Sample Input

    2 2

    3 4

    4 3

    0 0

    7

    103

    63

     

     

    Illustration of the first sample input:

    A floating-point number that has two bits for mantissa and two bits for exponent can represent the following values (Not less than 1) 1.000000, 1.250000, 1.500000, 1.750000, 2.000000, 2.500000, 3.000000, 3.500000, 4.0000005.0000006.000000 and 7.000000. Of these values only 7 values are integers.

    Problemsetter: Shahriar Manzoor

    Special Thanks: Md. Mahbubul Hasan

     
     
     
     
    我为何如此的的弱  
    /*
      记得预处理 还有就是 那么long long 的类型不能 有位移 大于int范围位移就出错了 
      然后还有 自己也是比较的坑啊  那个 题目看了很久才理解然后就 我为何如此的弱  
    */
    #include <iostream>
    #include <string.h>
    #include <cstdio>
    using namespace std;
    int n,m;
    long long ans,L,M,K;
    long long N[61];
    int main()
    {
        int n,m,a;
        L=1;
        for(int i=0;i<=61;i++)
        {
            N[i]=L;
            L=L*2;
        }
       while(scanf("%d%d",&n,&m)==2){
            if(n==0&&m==0) break;
        ans=0;
        L=1;
        M=0;
        a=n+1;
        M=N[m]-1;
        if(a>=M){
            ans=N[M]-1;
        }
        else {
           ans=N[n+1]-1;
           L=N[n];
           ans=ans+L*(M-n-1);
        }
        cout<<ans<<endl;
       }
        return 0;
    }
    

     
  • 相关阅读:
    桌面上嵌入窗口(桌面日历)原理探索(将该窗口的Owner设置成桌面的Shell 窗口,可使用SetWindowLong更改窗口的GWL_HWNDPARENT,还要使用SetWindowPos设置Z-Order)
    QQ截图时窗口自动识别的原理(WindowFromPoint, ChildWindowFromPoint, ChildWindowFromPointEx,RealChildWindowFromPoint)
    如何给开源的DUILib支持Accessibility(论述了DUILib的六个缺点,很精彩)
    从点击Button到弹出一个MessageBox, 背后发生了什么(每个UI线程都有一个ThreadInfo结构, 里面包含4个队列和一些标志位)
    Sessions, Window Stations and Desktops(GetDesktopWindow函数得到的桌面句柄, 是Csrss.exe创建的一个窗口)
    skip list
    理解对象模型图(Reading OMDS)
    Javascript与当前项目的思考
    Stub和Mock的理解
    https学习总结
  • 原文地址:https://www.cnblogs.com/Opaser/p/3662069.html
Copyright © 2011-2022 走看看