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
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[],y[]; int main()
{
long long a,b;
while(scanf("%lld%lld",&a,&b)!=EOF)
{
long long now=;
long long cnt=;
if(a>) a--;
for(long long i=1LL;i<=*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 ;
}
HDU 4588 Count The Carries 数学的更多相关文章
- HDU 4588 Count The Carries 计算二进制进位总数
点击打开链接 Count The Carries Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java ...
- HDU 4588 Count The Carries(数学统计)
Description One day, Implus gets interested in binary addition and binary carry. He will transfer al ...
- HDU 4588 Count The Carries (数学,计数)
题意:给定两个十进制数,求二进制中,从x加到y的二进制进了多少位. 析:把这些数字的二进制纵向罗列出来,然后一位一位的把和加起来,最终得到总的进位数.从1到x,第i位上1的总数是x左移i+1位再右移i ...
- HDU 4588 Count The Carries(找规律,模拟)
题目 大意: 求二进制的a加到b的进位数. 思路: 列出前几个2进制,找规律模拟. #include <stdio.h> #include <iostream> #includ ...
- hdu 4588 Count The Carries
思路:容易发现二进制表示的数的最低位规律是01010101……:接着是001100110011……:接着是:0000111100001111…… 这样我们发现每一位的循环节是2^(i+1),前2^i是 ...
- HDU 4588 Count The Carries 数位DP || 打表找规律
2013年南京邀请赛的铜牌题...做的非常是伤心.另外有两个不太好想到的地方.. ..a 能够等于零,另外a到b的累加和比較大.大约在2^70左右. 首先说一下解题思路. 首先统计出每一位的1的个数, ...
- HDU 4472 Count(数学 递归)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4472 Problem Description Prof. Tigris is the head of ...
- HDU 3336 Count the string(KMP的Next数组应用+DP)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 5459 Jesus Is Here 数学
Jesus Is Here Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
随机推荐
- FFmpeg在Android使用3
android 移植ffmpeg后so库的使用 只需要将我们编译好的ffmpeg的so包(在/obj/local/armeabi/libffmpeg.so)copy到所在ndk下的\platfor ...
- GreenDao官方文档翻译(上)
笔记摘要: 上一篇博客简单介绍了SQLite和GreenDao的比较,后来说要详细介绍下GreenDao的使用,这里就贴出本人自己根据官网的文档进行翻译的文章,这里将所有的文档分成上下两部分翻译,只为 ...
- Github 终于开始认真考虑开源项目许可证了
如今GitHub已成为全球最流行的开源项目托管平台,但也有质疑声音——“Github中的大多数项目并不算是开源项目”.这是因为Github中大多数项目并没有明确声明所使用的许可证. 根据版权法规定,如 ...
- 关于KOBE 退役
今天在网上看到一行话,写在KOBE 退役之际 关于职业,最值得问的是自己我有没有像科比那样始终表现出对团队的忠诚和对职业的热爱?从不被别人的误解和攻击打倒?在团队最困难的时候站出来做能做的一切?用职业 ...
- 简单把webdriver的find_element方法写成函数
__author__ = 'jyd' from selenium.webdriver.common.by import By #driver webdriver实例化对象 #element 查询元素的 ...
- ubuntu 下 数学库编译链接时找不到各种数学问题解决方法 can not fon atan 等等
解决参考 http://askubuntu.com/questions/190246/ld-cannot-find-math-library you should use -lm at the end ...
- Python 变量 对象 引用
1.变量 变量第一次赋值时被创建,变量在使用前必须赋值 变量本身没有类型,变量类型为它引用的对象类型: 变量在使用时被替换成它引用的对象 2.对象 对象本身具有计数和类型,变量引用对象,当对象的引用变 ...
- XNA Game Studio 4.0 Programming 随便读,随便记 “Rendering Text”
在游戏中,通常要与玩家交流,比如分数,提示等.这就需要一种新的精灵, 它就叫SpritFont.下面先将其增加到项目中: 项目 -----> 添加新项-----> Sprite Font ...
- Directory.GetCurrentDirectory
1.一个应用程序中,Directory.GetCurrentDirectory获得的当前工作目录是C:\Windows\System32,这是为什么呢?是如何设置的? 2.在WinXP下:System ...
- Codeforces 375
A 7的所有的余数都可以用1,6,8,9排列得到,然后搞一下就可以了. B 可以用类似于单调队列的东西搞.具体看代码: /* * Problem: B. Maximum Submatrix 2 * A ...