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,如果直接记录下数字, ...
随机推荐
- 基于layui的框架模版,采用模块化设计,接口分离,组件化思想
代码地址如下:http://www.demodashi.com/demo/13362.html 1. 准备工作 编辑器vscode,需要安装liveServer插件在前端开启静态服务器 或者使用hbu ...
- 解决——CSS :before、:after ,当content使用中文时有时候会出现乱码
问题: 在进行页面开发时,经常会使用:before, :after伪元素创建一些小tips,但是在:before或:after的content属性使用中文的话,会导致某些浏览器上出现乱码. 例如我遇到 ...
- php中对象是引用类型吗?
这貌似是一个极其简单的问题,还用得着专门写一篇博文?各位看官,最初我也这么认为,但这的确蒙蔽了你那水灵灵的小眼睛,不妨看看什么是引用? $a = 10; $b = &$a; $b = 20; ...
- app产品设计碉堡了
这个项目碉堡了 http://blog.csdn.net/googdev/article/details/54849715 2017-02-03 22:15 3898人阅读 评论(12) 收藏 举报 ...
- Mysql的replace into语句
Mysql语句 replace into 跟 insert 功能类似,不同点在于:replace into 首先尝试插入数据到表中, 1. 如果发现表中已经有此行数据(根据主键或者唯一索引判断)则先删 ...
- Javascript实现真实字符串剩余字数提示
//文本框剩余字数提示(字符大小) function textLimitCheckSj(thisArea, maxLength, SpanId) { var str = thisArea.value; ...
- Spark-shell 启动WARN---java.net.BindException: Address already in use
同时打开了两个SecureCRT的终端界面,其中一个已经进入了Spark-shell,在另一个SecureCRT界面中执行 "spark-shell --master yarn --depl ...
- 未设置BufferSize导致FTP下载速度过慢的问题
開始下载前设置BufferSize就可以解决: ftpClient.setBufferSize(1024*1024); 查看commons-net的源代码.能够发现假设未设置该參数.将会一个字节一个字 ...
- NGUI拖拽简介
挂上UIDragDropItem就可以实现拖拽,按钮监听Drop消息即可实现对拖放的监听. UIDragDropItem有一个Clone On Drag选项,勾上可以克隆,但会被ScrollView遮 ...
- Atitit.二维码功能的设计实践 attilax 总结
Atitit.二维码功能的设计实践 attilax 总结 1.1. 二维码要实现的功能1 1.2. 现有二维码功能设计不足的地方(待改进)1 1.3. 二维码组件1 1.4. Java版 zxing ...