hdu 4588 Count The Carries
思路:容易发现二进制表示的数的最低位规律是01010101……;接着是001100110011……;接着是:0000111100001111……
这样我们发现每一位的循环节是2^(i+1),前2^i是0,后面的是1.这样就可以算出每一位1出现的次数。
代码如下:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define ll __int64
using namespace std;
ll a[]={,,,,,,,,,,,,,,,
,,,,,,,,,
,,,,,,,
,,,};
ll sa[],sb[],s[];
int get(int n)
{
int bit=;
while(n){
bit++;
n>>=;
}
return bit;
}
void solve(int n,ll *aa)
{
ll i,j,nn=n+;
if(n<=) return;
int len=get(n);
for(int k=;k<len;k++){
aa[k]+=nn/a[k+]*a[k];
j=nn%a[k+];
if(j>=a[k]) j-=a[k];
else j=;
aa[k]+=j;
}
}
int main()
{
int n,m,len1,len2;
ll c;
while(scanf("%d%d",&n,&m)!=EOF){
memset(sa,,sizeof(sa));
memset(sb,,sizeof(sb));
memset(s,,sizeof(s));
solve(m,sa);
solve(n-,sb);
for(int i=;i<;i++) s[i]=sa[i]-sb[i];
ll ans=;
for(int i=;i<;i++){
c=(s[i]>>);
ans+=c;
s[i+]+=c;
}
printf("%I64d\n",ans);
}
return ;
}
hdu 4588 Count The Carries的更多相关文章
- HDU 4588 Count The Carries 数学
Count The CarriesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- 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(找规律,模拟)
题目 大意: 求二进制的a加到b的进位数. 思路: 列出前几个2进制,找规律模拟. #include <stdio.h> #include <iostream> #includ ...
- HDU 4588 Count The Carries (数学,计数)
题意:给定两个十进制数,求二进制中,从x加到y的二进制进了多少位. 析:把这些数字的二进制纵向罗列出来,然后一位一位的把和加起来,最终得到总的进位数.从1到x,第i位上1的总数是x左移i+1位再右移i ...
- HDU 4588 Count The Carries 数位DP || 打表找规律
2013年南京邀请赛的铜牌题...做的非常是伤心.另外有两个不太好想到的地方.. ..a 能够等于零,另外a到b的累加和比較大.大约在2^70左右. 首先说一下解题思路. 首先统计出每一位的1的个数, ...
- 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) ...
- Count The Carries
hdu:http://acm.hdu.edu.cn/showproblem.php?pid=4588 题意:给你 a,b两个数,然后让a到b之间的数做2进制的加法,问你与多少次进位.例如:1,3,1+ ...
- HDU 5901 Count primes 论文题
Count primes 题目连接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5901 Description Easy question! C ...
随机推荐
- 错误解决mysql - Event Scheduler: No data - zero rows fetched, selected, or processed
当遇到一个NOT FOUND(无数据)的警告时,使用一个包含清除警告语句的条件句柄处理,就可以继续处理程序并退出句柄. 这个问题在MySQL5.6.3之后的版本已经解决了,所以该解决方法不是必要的. ...
- winform Config文件操作
using System;using System.Collections.Generic;using System.Text;using System.Xml;using System.Config ...
- C# Winform中DataGridView的DataGridViewCheckBoxColumn使用方法
下面介绍Winform中DataGridView的DataGridViewCheckBoxColumn使用方法: DataGridViewCheckBoxColumn CheckBox是否选中 在判断 ...
- Func 委托
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- sql server 中 bigint 和 datetime 性能比较
-- 创建表 create table Test_tbl ( ID varchar(40) primary key nonclustered, IntCol int, DateCol datetime ...
- wordpress修改固定链接及修改链接后链接提示404错误的解决办法
wordpress默认的url实在是不好看又不好记忆,而且还不利于SEO.因此,我就捣鼓着把url做一个自定义.自定义的方式如下: 建议使用/%postname%的形式,这样利于SEO. 修改之后,l ...
- gcc链接程序时出现undefined reference to""错误
如:: undefined reference to ‘mq_unlink',意思是指函数mq_unlink没有定义. 可以使用如下步骤找到该函数所在的库: 1).查找哪些库包含了或使用了该函数:gr ...
- require.js入门指南(二)
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- 【转】如何在 Windows 中执行干净启动
完成故障排除后,请执行以下步骤将计算机重置为正常启动. Windows 8.1 和 Windows 8 从屏幕右边缘滑入,然后点按“搜索”.您也可以将鼠标指向屏幕的右下角,然后单击“搜索”. 在搜索框 ...
- 【Go】为什么用go; Golang Erlang 前世今生
给自己一条退路,再次比较Erlang和Golang 2014-6-28 陈叶皓 chenyehao@gmail.com 雨天的周末,适合码字的时节... 一年前我开始学习go语言的时候,如获至宝,既有 ...