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,如果直接记录下数字, ...
随机推荐
- 登录首页时报错:java.lang.IllegalArgumentException (不合法的参数异常)
处理一个老项目,DOWN下项目并配好之后,启动没问题,但是登陆之后首页显示如下: 控制台报错如下: 严重: Servlet.service() for servlet jsp threw except ...
- sql 中 ALTER 和 UPDATE 的区别
alter 是DDL语句,是修改数据库中对象(表,数据库,视图..)的语句. 如需在表中添加列,请使用下面的语法: ALTER TABLE table_name ADD column_name dat ...
- java集合框架01——总体框架一览
java集合框架是java提供的工具包,在java.util.*中,这个包中包含了常用的数据结构:集合.数组.链表.栈.队列.映射等.java集合框架主要可以分为四个部分:List列表.Set集合.M ...
- Service stopSelf(int statId)和onStartcommand(Intent intent,int flags,int startId)
Stopping a service A started service must manage its own lifecycle. That is, the system does not sto ...
- C语言printf格式化输出修饰符详解
转换说明 输出 %a,%A 浮点数.十六进制数和p-计数法(C99) %c 一个字符 %d 有符号十进制数 %e,%E 浮点数,e计数法 %f 浮点数,十进制计数法 %g,%G 根据数值不同自动选择% ...
- Python 实现字符串转换成列表 实现str转换list
其中Python strip() 方法用于移除字符串头尾指定的字符 split()就是将一个字符串分裂成多个字符串组成的列表 >>> image ='1.jsp,2.jsp,3.js ...
- ListView局部更新(非notifyDataSetChanged)
package com.example.test; import java.util.ArrayList; import java.util.List; import android.app.Acti ...
- Java生成随机不反复推广码邀请码
欢迎进入我的博客:blog.scarlettbai.com查看很多其它文章 近期接到一个需求.要批量生成推广码,首先我们知道推广码的特效有例如以下两点: 1:不可反复 2:不能够被猜測出 关于这两点, ...
- 第三篇:python函数
1.python函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.你已经知道Python提供了许多内建函数,比如print().但你 ...
- (转)Python开发规范
转自:https://www.jianshu.com/p/d414e90dc953 Python风格规范 本项目包含了部分Google风格规范和PEP8规范,仅用作内部培训学习 Python风格规范 ...