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= ...
随机推荐
- 【unity3D】鼠标控制camera的移动、放大(俯视浏览效果、LOL摄像机移动效果)
在Unity开发中,用鼠标滚轮来实现摄像机的视野范围,鼠标左键拖拉控制摄像机的移动,代码如下: 1.俯视浏览效果 using UnityEngine; using System.Collections ...
- Ruby基础数据类型
#数字分为证书Integer,浮点数Float(对应与其他语言中的double),和复数Complex #整数又分为Fixnum和Bignum,Fixnum和Bignum会互相转换,这些都是ruby自 ...
- Java与WCF交互(一)补充:用WSImport生成WSDL的Java客户端代码
在<Java与WCF交互(一):Java客户端调用WCF服务>一 文中,我描述了用axis2的一个Eclipse控件生成WCF的Java客户端代理类,后来有朋友建议用Xfire.CXF,一 ...
- ECshop 二次开发模板教程1
本教程适用于了解 ECshop 和 ECshop模板DIY 以及它们的日常使用,在查看前阁下需要至少会使用一种编辑器(exp:Dreamweaver, editplus, emacs, vi, ee ...
- matlab中图像处理常见用法
一. 读写图像文件 1. imread imread函数用于读入各种图像文件,如:a=imread('e:/w01.tif') 注:计算机E盘上要有w01相应的.tif文件. 2. imwrite i ...
- storm,hbase和storm-kafka-0.8-plus兼容性问题
1 org.slf4j.impl.StaticLoggerBinder.SINGLETON错误 方案: 确保slf4j-api-1.5.6.jar 和slf4j-log4j12-1.5.6.jar ...
- Maven管理多模块项目
首先,我们要明确的多模块项目的含义,它是指一个应用中包含多个module.一般来说,一个应用单独部署成服务,只是打包的时候,maven会把各个module组合在一起.各模块一般单独打成jar放到lib ...
- 【bz2002】弹飞绵羊
题意: 给出n个节点 及其父亲 和m个指令1:表示求节点i到根节点(n+1)的距离2:表示将节点i的父亲更换为j 题解: 动态树link.cut.access模板题 貌似没什么难度- - 代码: #i ...
- http 名词解释
get.post.put.delete的安全性和幂等性 安全性:指的是对资料是否有破坏性的操作 幂等性:指的是对资源操作时,数据是一致性.
- lsof,nc
安装nc, yum -y install nc; 用nc传输同步文件 A,被同步端-即需要备份复制端; tar -czvf - /|nc 192.168.1.204(同步机ip,复制文件位置机) 88 ...