链接

去年南京邀请赛的水题,当时找规律过的,看它长得很像数位dp,试了试用数位dp能不能过,d出每位上有多少个1,然后TLE了。。然后用规律优化了前4位,勉强过了。

附数位dp代码及找规律代码。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<stdlib.h>
#include<map>
using namespace std;
#define N 1000000
#define LL __int64
int dp[][][];
int di[],o[],oo[];
int s[N][],tg,pp[];
bool f[N];
int dfs(int i,int e,bool z,int k)
{
if(i<) return z;
if(!e&&dp[i][k][z]!=-) return dp[i][k][z];
int mk = e?di[i]:;
int ans = ;
for(int j = ; j <= mk ; j++)
{
int ct = dfs(i-,e&&(j==mk),(z|((i==k)&&j)),k);
ans+=ct;
}
return e?ans:dp[i][k][z] = ans;
}
int cc(int x,int k)
{
int p1 = (x-pp[k]+)/pp[k+];
int qq = p1*pp[k];
if((x-pp[k]+)%pp[k+]>pp[k]) qq += pp[k];
else qq+=((x-pp[k]+)%pp[k+]);
return qq;
}
//void cal(int x,int y)
//{
// int g = 0,i;
// int tx = x;
// memset(o,0,sizeof(o));
// if(x<=0)
// o[0] = o[1] = 0;
// else{
// o[0] = (x+1)/2;
// o[1] = cc(x,1);
// if(x>=3)
// o[2] = cc(x,2);
// if(x>=7)
// o[3] = cc(x,3);
// }
// while(x>0)
// {
// di[g++] = x%2;
// x/=2;
// }
// for(i = 4 ; i <= g-1 ; i++)
// {
// o[i] = dfs(g-1,1,0,i);
// }
// int t = 0;
// LL ans = 0;
// if(y<=0)
// oo[0] = oo[1] = o[2] = o[3] = 0;
// else{
// oo[0] = ((y+1)/2);
// oo[1] = cc(y,1);
// if(y>=3)
// oo[2] = cc(y,2);
// if(y>=7)
// oo[3] = cc(y,3);
// }
// g = 0;
// while(y)
// {
// di[g++] = y%2;
// y/=2;
// }
// for(i = 4 ;i <= g-1 ; i++)
// {
// oo[i] = dfs(g-1,1,0,i);
// }
// for(i = 0 ; i <= g-1; i++)
// {
// t = (t+oo[i]-o[i])/2;
// ans+=t;
// }
// while(t)
// {
// t = (t)/2;
// ans+=t;
// }
// printf("%I64d\n",ans);
//}
LL cal(int a,int b)
{
LL ans = ;
int t = ,s1,s2;
if(a>=) s1 = (a+)/;
if(b>=) s2 = (b+)/;
t = (s2-s1)/;
ans+=t;
for(int i = ;i < ;i++)
{
if(a>=pp[i]) s1 = cc(a,i);
else s1=;
if(b>=pp[i]) s2 = cc(b,i);
else s2=;
t = (t+s2-s1)/;
ans+=t;
}
while(t)
{
t/=;
ans+=t;
}
return ans;
}
int main()
{
int a,b;
pp[] = ;
for(int i = ; i < ; i++)
pp[i] = pp[i-]*;
memset(dp,-,sizeof(dp));
int t = ;
while(scanf("%d%d",&a,&b)!=EOF)
{
if(a==b)
printf("0\n");
else
printf("%I64d\n",cal(a-,b));
}
return ;
}

hdu4588Count The Carries的更多相关文章

  1. ACM:SCU 4437 Carries - 水题

    SCU 4437  Carries Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practice  ...

  2. 2015弱校联盟(1) - B. Carries

    B. Carries Time Limit: 1000ms Memory Limit: 65536KB frog has n integers a1,a2,-,an, and she wants to ...

  3. HDU 4588 Count The Carries 数学

    Count The CarriesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  4. HDU 4588 Count The Carries 计算二进制进位总数

    点击打开链接 Count The Carries Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java ...

  5. Carries SCU - 4437

    Carries frog has nn integers a1,a2,-,ana1,a2,-,an, and she wants to add them pairwise. Unfortunately ...

  6. 二分 + 模拟 - Carries

    Carries Problem's Link Mean: 给你n个数,让你计算这n个数两两组合相加的和进位的次数. analyse: 脑洞题. 首先要知道:对于两个数的第k位相加会进位的条件是:a%( ...

  7. HDU 4588 Count The Carries(数学统计)

    Description One day, Implus gets interested in binary addition and binary carry. He will transfer al ...

  8. Carries

    Carries frog has nn integers a1,a2,…,ana1,a2,…,an, and she wants to add them pairwise. Unfortunately ...

  9. HDU 4588 Count The Carries(找规律,模拟)

    题目 大意: 求二进制的a加到b的进位数. 思路: 列出前几个2进制,找规律模拟. #include <stdio.h> #include <iostream> #includ ...

随机推荐

  1. PRINCE2七大原则(1)

    PRINCE2七大原则(1) 我们先来回顾一下,PRINCE2七大原则分别是持续的业务验证,经验学习,角色与责任,按阶段管理,例外管理,关注产品,剪裁. 第二个原则:吸取经验教训. PRINCE2要求 ...

  2. [算法]判断一个数是不是2的N次方

    如果一个数是2^n,说明这个二进制里面只有一个1.除了1. a  = (10000)b a-1 = (01111)b a&(a-1) = 0. 如果一个数不是2^n, 说明它的二进制里含有多一 ...

  3. Winform中如何实现父窗体传递数据到子窗体并刷新子窗体

    原理:利用委托和事件,本文将以图文并茂的例子讲述,告诉我们So Easy --------------------------------------------------------------- ...

  4. c# web 缓存管理

    using System; using System.Collections; using System.Text.RegularExpressions; using System.Web; usin ...

  5. MessageFlood 分类: 串 2015-06-18 17:00 10人阅读 评论(0) 收藏

    MessageFlood TimeLimit: 1500ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Well,how do you feel about mobil ...

  6. ural 1112,LIS

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1112 题意:n根线段,要拿走一些,使得任何的线段的左段没有在某一个线段的内部. 其实说白 ...

  7. C#之猴子吃桃儿问题的解法——猴子吐桃儿

    猴子第一天摘了许多个桃子,先吃了所有桃子的一半,后又吃了一个:第二天又吃了剩下桃子的一半,后又吃了一个……第十天,剩1个桃子.问:猴子第一天摘了多少个桃子? 首先对“猴子吃桃”的过程进行正向推导,设: ...

  8. Reading package lists... Error! 解决方案

    ubuntu 下安装python开发包,执行命令 sudo apt-get install python-dev,报错: Reading package lists... Error! E: Enco ...

  9. 2016年12月12日 星期一 --出埃及记 Exodus 21:7

    2016年12月12日 星期一 --出埃及记 Exodus 21:7 "If a man sells his daughter as a servant, she is not to go ...

  10. 在repeater增加自增长的序号

    <td><%#Container.ItemIndex+ %></td> 完!!!