日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU 4588 Count The Carries 数学

發布時間:2024/4/14 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 4588 Count The Carries 数学 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Count The Carries
Time Limit: 20 Sec

Memory Limit: 256 MB

題目連接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87326#problem/C

Description

One day, Implus gets interested in binary addition and binary carry. He will transfer all decimal digits to binary digits to make the addition. Not as clever as Gauss, to make the addition from a to b, he will add them one by one from a to b in order. For example, from 1 to 3 (decimal digit), he will firstly calculate 01 (1)+10 (2), get 11,then calculate 11+11 (3),lastly 110 (binary digit), we can find that in the total process, only 2 binary carries happen. He wants to find out that quickly. Given a and b in decimal, we transfer into binary digits and use Implus's addition algorithm, how many carries are there?.

Input

Two integers a, b(0<=a<=b<1000000000), about 100000 cases, end with EOF.

Output

One answer per line.

Sample Input

1 2
1 3
1 4
1 6

Sample Output

0
2
3
6

HINT

?

題意

二進制累加,從A累加到B,問你在二進制中,一共進位了多少次

題解

我并不知道怎么做的……

隊友啪啪啪就拍完了= =

代碼:

#include <cstdio> #include <cstring> #include <iostream> #include <cstdlib> #include <algorithm>using namespace std;long long x[70],y[70];int main() {long long a,b;while(scanf("%lld%lld",&a,&b)!=EOF){long long now=0;long long cnt=0;if(a>0) a--;for(long long i=1LL;i<=60*1LL;i++){x[i]=(1LL<<(i-1LL))*(a>>i)+max(0LL,(a%(1LL<<i)-(1LL<<(i-1LL))+1LL));y[i]=(1LL<<(i-1LL))*(b>>i)+max(0LL,(b%(1LL<<i)-(1LL<<(i-1LL))+1LL));now+=y[i]-x[i];cnt+=1LL*(now>>1LL);now=now>>1LL;}while(now){cnt+=1LL*now;now>>=1LL;}printf("%lld\n",cnt);}return 0; }

?

轉載于:https://www.cnblogs.com/qscqesze/p/4722379.html

總結

以上是生活随笔為你收集整理的HDU 4588 Count The Carries 数学的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。