Count The Carries - HDU 4588 水题
来源:互联网 发布:解除端口占用的命令 编辑:程序博客网 时间:2024/06/05 22:17
Count The Carries
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1158 Accepted Submission(s): 383
Problem 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 21 31 41 6
Sample Output
0236
题意:从l加到r二进制进位一共发生多少次。
思路:预算出每个二进制位上共有多少个1,假设有n个1,那么这个位上的进位会发生n/2次。
AC代码如下:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;typedef long long ll;ll L,R;int T,t,n,m;ll num[110],POW[45];ll solve(ll ret,ll p){ int i,j; ll k,ans; ret++; k=ret/p; ans=k*p/2; ret=ret-k*p;; if(ret>p/2) ans+=ret-p/2; return ans;}int main(){ int i,j,k; ll ans,ret; POW[1]=2; for(i=2;i<=40;i++) POW[i]=POW[i-1]*2; while(~scanf("%I64d%I64d",&L,&R)) { memset(num,0,sizeof(num)); for(i=1;i<=40;i++) num[i]=solve(R,POW[i])-solve(L-1,POW[i]); ans=0; for(i=1;i<=100;i++) { ret=num[i]/2; num[i+1]+=ret; ans+=ret; } printf("%I64d\n",ans); }}
0 0
- Count The Carries - HDU 4588 水题
- HDU 4588 Count The Carries
- hdu 4588 Count The Carries
- hdu 4588 Count The Carries
- HDU 4588 Count The Carries
- HDU 4588Count The Carries
- HDU 4588 Count The Carries 题解
- 数学题-hdu-4588-Count The Carries
- hdu 4588 Count The Carries 南京邀请赛
- hdu 4588 Count The Carries(数论)
- 【瞎搞】 HDU 4588 Count The Carries
- HDU-4588 Count The Carries (模拟)
- HDU 4588 Count The Carries(规律)
- HDU 4588 Count The Carries(数学)
- Hdu 4588 Count The Carries (规律)
- HDU 4588 Count The Carries(数学 找规律)
- hdu 4588Count The Carries(循环节 规律题目)
- HDU 4588 Count The Carries 计算二进制进位总数
- 纯JS俄罗斯方块
- hibernate 显示完整的SQL
- java实现约瑟夫环问题
- 数据结构:有向图的十字链表存储表示(c实现)
- Cygwin下编译MySQL后启动遇到的问题
- Count The Carries - HDU 4588 水题
- C语言数组名与指针
- Freertos 二元信号量
- Android 实现borderless的Button并设置分界线
- 黑马程序员—java基础_IO流—字节流
- java不定参数列表---乔老师没讲,但是传智有讲
- js去掉空格回车换行
- JAVA中的流学习
- JavaScript常用记录(2)