链接

去年南京邀请赛的水题,当时找规律过的,看它长得很像数位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. HLS视频直播

    HTTP Live Streaming (HLS) 苹果官方对于视频直播服务提出了 HLS 解决方案,该方案主要适用范围在于: 使用 iPhone .iPod touch. iPad 以及 Apple ...

  2. 各种drawable

    BitmapDrawable   可以把小图片平铺布满布局来设置背景. PictureDrawable    记录绘制过程 ClipDrawable     裁剪   进度条 InsetDrawabl ...

  3. Rigidbody.position/rotation更新测试

    Rigidbody.position/rotation主要提供在下一个物理步之前更新物理位置,一般用于SweepTest这样的接口 那么测试一下会不会修改掉transform.position的值 测 ...

  4. 理解mipi协议

    完成mipi信号通道分配后,需要生成与物理层对接的时序.同步信号: MIPI规定,传输过程中,包内是200mV.包间以及包启动和包结束时是1.2V,两种不同的电压摆幅,需要两组不同的LVDS驱动电路在 ...

  5. jquery uploadify上传插件兼容火狐问题

    jquery uploadify长传插件兼容火狐问题.因为现在火狐以不在默认安装flash插件.所以uploadify的flash版就需要安装flash插件.还可以成功. 可以到哪里下载安装:http ...

  6. 解决json_encode中文UNICODE转码问题

    用PHP的json_encode来处理中文的时候, 中文都会被编码, 变成不可读的, 类似”\u***”的格式,如果想汉字不进行转码,这里提供三种方法 .升级PHP,在PHP5., 这个问题终于得以解 ...

  7. ios kaifa

    弹窗提示 { ////ios 7 弹窗 // UIAlertView *alert1=[[UIAlertView alloc] // initWithTitle:@"tishi" ...

  8. drawRect导致内存暴增的真正原因

    那么现在我们分析一下drawRect导致内存暴增的真正原因: 重写drawRect为何会导致内存大量上涨? 要想搞明白这个问题,我们需要撸一撸在 iOS 程序上图形显示的原理.在 iOS 系统中所有显 ...

  9. Runtime运行时的那点事儿

    注:本文是对 Colin Wheeler 的 Understanding the Objective-C Runtime 的翻译. 初学 Objective-C(以下简称ObjC) 的人很容易忽略一个 ...

  10. SqlSever基础 dateadd month 增加五个月

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...