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,如果直接记录下数字, ...
随机推荐
- Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.7
导入maven项目时,pom.xml文件报错如下: Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2. ...
- spring jdbc框架
spring+jdbc 1.jdbc编程的特点: 模板编程 固定代码+动态的参数 spring产生dataSource JdbcTemplate{//模板编程 private DataSource d ...
- Linux日知录(常用问题笔记)
http://blog.csdn.net/yizhu2000/article/details/70688420)序言 日有一知,当有一录,自09年来,工作所需,接触开源平台,对Linux常有涉猎,其间 ...
- poj_2773
题目的愿意非常easy.给你一个n,求在升序排列的情况下,第k个与之相互素的数. 解法:首先我们要知道gcd(b×t+a,b)=gcd(a.b),那么接下来就非常easy了.全部与之互素的数都是以ph ...
- Solr3.6.2和Solr4.9.0经常使用配置
tomcat 以tomcat 7为例,位置/work/apache-tomcat-7.0.55 Solr 3.6.2 基本配置 Solr 3.6.2.须要JDK 6/JDK7支持. 下载Solr 3. ...
- ext4文件系统(转)
[ext4]01 磁盘布局 - block分析 [ext4]02磁盘布局 - group分析 [ext4]03 磁盘布局 – Flexible group分析 [ext4]04 磁盘布局 - Meta ...
- Android错误之--activity_main cannot be resolved or is not a field
一般在copy别人的项目中会easy出现本错误,截图例如以下:
- 手动安装minGW
minGW是C语言编译包,将GCC编译器在Windows平台上编译软件提供支持. 手工安装minGW是一件很繁琐的事情,但是搞懂它很有用,因为C语言本身是一个很小的语法系统,全靠 各种库在支持,安装m ...
- JavaNIO - AbstractInterruptibleChannel
1. 描述 可异步关闭和中断的Channel. (1)实现InterruptibleChannel接口的Channel支持异步关闭:如果一个线程IO阻塞在一个可中断的channel,另一个线程可以执行 ...
- npm太慢, 淘宝npm镜像使用方法[转]
淘宝 npm 地址: http://npm.taobao.org/ 如何使用 有很多方法来配置npm的registry地址,下面根据不同情境列出几种比较常用的方法.以淘宝npm镜像举例: 1.临时使用 ...