zoukankan      html  css  js  c++  java
  • 求a加到b二进制加法有多少次进位。

    //求a加到b二进制加法有多少次进位。
    //网址:http://219.230.70.12/Local/1739
    #include<cstdlib>
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<cstring>
    #include<algorithm>
    #include<set>
    #include<map>
    #include<list>
    #include<queue>
    #include<vector>
    #define ULL unsigned long long
    #define LL long long
    #define UI unsigned int
    #define inf 0x7fffffff
    #define eps 1e-7
    #define N 1009
    #define M 20009
    using namespace std;
    int T,n,m,k,t;
    int a[N],b[N],la,lb,x,y;
    void fun(int x,int &top,int a[])
    {
        int t=1;
        top=0;
        while((x)>=t)
        {
            t*=2;
            a[top]=((x+1)/t)*(t/2);
            a[top]+=max(0,((x+1)%t)-t/2);
            top++;
        }
    }
    int main()
    {
    #ifndef ONLINE_JUDGE
        freopen("ex.in","r",stdin);
    #endif
        int ncase=0;
    //    scanf("%d",&T);
        while (scanf("%d%d",&x,&y)!=EOF)
    //    while (T--)
        {
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            fun(x-1,la,a);
            fun(y,lb,b);
            int num=0;
            LL ans=0;
            for(int i=0; i<lb||num; i++)
            {
                int t=0;
                if(i<lb)
                    t=b[i]-a[i];
                t+=num;
                ans+=t/2;
                num=t/2;
            }
            cout<<ans<<endl;
        }
        return 0;
    }
    

      

  • 相关阅读:
    Source Insight新建工程文件
    移植3.4.2内核之韦东山笔记
    移植最新u-boot(裁剪和修改默认参数)
    C++与C语言在结构体上的区别
    VIP之Switch
    VIP之CSC
    VIP之Scaler
    VIP之FrameBuffer
    VIP之MixerII
    VIP之Clipper
  • 原文地址:https://www.cnblogs.com/sbaof/p/3078399.html
Copyright © 2011-2022 走看看