bunoj 13124(数位dp)
数位dp每次都给我一种繁琐的感觉。。
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Description
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the same when its digits are reversed. In this problem you will be given two integers i j, you have to find the number of palindromic numbers between i and j (inclusive).
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case starts with a line containing two integers i j (0 ≤ i, j ≤ 1017).
Output
For each case, print the case number and the total number of palindromic numbers between i and j (inclusive).
Sample Input
4
1 10
100 1
1 1000
1 10000
Sample Output
Case 1: 9
Case 2: 18
Case 3: 108
Case 4: 198
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <sstream>
#include <iostream>
using namespace std;
#define INF 0x3fffffff typedef __int64 LL; LL save[];
int bit[];
int cnt;
LL dp[]; LL get(LL x)
{
if(x==) return ;
LL tx=x;
cnt=;
while(x)
{
bit[++cnt]=x%;
x/=;
}
LL ans=;
ans=dp[cnt-];
for(int i=;i<bit[cnt];i++)
{
if(cnt->=)
ans+=save[cnt-];
else ans++;
}
if(cnt==) return ans+; //
int tmp=;
for(int i=;i<=(cnt+)/;i++)
{
if( cnt-tmp>=)
ans += save[cnt-tmp]*bit[cnt-i+];
else ans += bit[cnt-i+];
tmp+=;
}
int bit1[]; for(int i=;i<=(cnt+)/;i++)
{
bit1[cnt-i+]=bit[cnt-i+];
bit1[i]=bit[cnt-i+];
} // LL sum=;
for(int i=cnt;i>=;i--)
sum=sum*+bit1[i];
if(sum<=tx) ans++;
return ans;
} void dfs(int s)
{
LL sum=;
if(s==)
{
dp[]=;
return ;
}
dfs(s-);
sum += dp[s-];
sum += *(save[s-]);
dp[s]=sum;
} int main()
{
//freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//freopen("C:\\Users\\Administrator\\Desktop\\in.txt","w",stdout);
save[]=;
for(int i=;i<=;i++)
{
LL tmp=;
if(i%==)
{
for(int j=;j<i/;j++)
tmp*=;
}
else
{
for(int j=;j<i/+;j++)
tmp*=;
}
save[i]=tmp;
}
dp[]=;
dfs();
int T;
scanf("%d",&T);
int tt=;
int kk=;
for(int i=;i<=;i++)
kk++; while(T--)
{
LL a,b;
cin>>a>>b;
if(a>b) swap(a,b);
if(a==)
{
a=;
}
else
a=get(a-);
b=get(b);
cout<<"Case "<<tt++<<": ";
cout<<b-a<<endl;
}
return ;
}
bunoj 13124(数位dp)的更多相关文章
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- bzoj1026数位dp
基础的数位dp 但是ce了一发,(abs难道不是cmath里的吗?改成bits/stdc++.h就过了) #include <bits/stdc++.h> using namespace ...
- uva12063数位dp
辣鸡军训毁我青春!!! 因为在军训,导致很长时间都只能看书yy题目,而不能溜到机房鏼题 于是在猫大的帮助下我发现这道习题是数位dp 然后想起之前讲dp的时候一直在补作业所以没怎么写,然后就试了试 果然 ...
- HDU2089 不要62[数位DP]
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 数位DP GYM 100827 E Hill Number
题目链接 题意:判断小于n的数字中,数位从高到低成上升再下降的趋势的数字的个数 分析:简单的数位DP,保存前一位的数字,注意临界点的处理,都是套路. #include <bits/stdc++. ...
- 数位dp总结
由简单到稍微难点. 从网上搜了10到数位dp的题目,有几道还是很难想到的,前几道基本都是模板题,供入门用. 点开即可看题解. hdu3555 Bomb hdu3652 B-number hdu2089 ...
- 数位DP入门
HDU 2089 不要62 DESC: 问l, r范围内的没有4和相邻62的数有多少个. #include <stdio.h> #include <string.h> #inc ...
- 数位DP之奥义
恩是的没错数位DP的奥义就是一个简练的dfs模板 int dfs(int position, int condition, bool boundary) { ) return (condition ? ...
- 浅谈数位DP
在了解数位dp之前,先来看一个问题: 例1.求a~b中不包含49的数的个数. 0 < a.b < 2*10^9 注意到n的数据范围非常大,暴力求解是不可能的,考虑dp,如果直接记录下数字, ...
随机推荐
- Drupal显示白屏或500?
Drupal有时会显示白屏,或者500内部错误,这多半是由于PHP脚本什么地方有问题造成的.这个时候,可以先看看php.log里面有没有提示: [10-Oct-2013 15:55:26 Asia/S ...
- Spring集成Redis集群(含spring集成redis代码)
代码地址如下:http://www.demodashi.com/demo/11458.html 一.准备工作 安装 Redis 集群 安装参考: http://blog.csdn.net/zk6738 ...
- 利用Redis撤销JSON Web Token产生的令牌
利用Redis撤销JSON Web Token产生的令牌 作者:chszs.版权全部.未经允许,不得转载.博主主页:http://blog.csdn.net/chszs 早先的博文讨论了在Angula ...
- Backbone.js 1.0.0源码架构分析(二)——Event
(function(){ //省略前面代码 var Events = Backbone.Events = { // 根据name订阅事件,push到this._events[name] on: fun ...
- Struts2对于i18n的支持
struts.xml中可以配置 <constant name="struts.custom.i18n.resources" value="itcast"& ...
- kettle--组件(3)--行转列
组件图如下: 以上操作可以这么理解: IF(DATA1=DATA4) THEN DATA2=DATA3 也就是关键字值的数值会与关键字段的数值匹配,匹配上了就显示数据value filedname所填 ...
- json再理解
一.Json的简单介绍 从结构上看,所有的数据最终都可以分成三种类型: 第一种类型是scalar(标量),也就是一个单独的string(字符串)或数字(numbers),比如“北京”这个单独的词. 第 ...
- Python 实现根据不同的程序运行环境存放日志目录,Python实现Linux和windows系统日志的存放
说明:在我们开发的时候,有时候是在windows系统下开发的代码,我们的生产环境是Linux系统,更新代码就需要修改日志的环境,本文实现了代码更新,不需要配置日志文件的目录,同样也可以延伸到ip地址 ...
- Hyper-V 虚拟机无法上网的解决方法
创建一个虚拟机网络交换机 2 创建一个 外部网络如下图所示: 3 添加一个旧版的网络适配器: 4 设置旧版网络适配器: END XP系统的情况 1 启动虚拟机,设置虚拟机IP: 2 输入http:// ...
- ((void *) 0)的含义和void的一些细节
一.在c语言中,0是一个特殊的值,它可以表示:整型数值0,空字符,逻辑假(false).表示的东西多了,有时候不好判断.尤其是空字符和数字0之间. 为了明确的指出,0是空字符的含义,用用到了: (() ...