Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)
Total Submission(s): 662    Accepted Submission(s): 351

Problem Description

As we all know,a palindrome number is the number which reads the same backward as forward,such as 666 or 747.Some numbers are not the palindrome numbers in decimal form,but in other base,they may become the palindrome number.Like 288,it’s not a palindrome number under 10-base.But if we convert it to 17-base number,it’s GG,which becomes a palindrome number.So we define an interesting function f(n,k) as follow:
f(n,k)=k if n is a palindrome number under k-base.
Otherwise f(n,k)=1.
Now given you 4 integers L,R,l,r,you need to caluclate the mathematics expression ∑Ri=L∑rj=lf(i,j) .
When representing the k-base(k>10) number,we need to use A to represent 10,B to represent 11,C to repesent 12 and so on.The biggest number is Z(35),so we only discuss about the situation at most 36-base number.

Input

The first line consists of an integer T,which denotes the number of test cases.
In the following T lines,each line consists of 4 integers L,R,l,r.
(1≤T≤105,1≤L≤R≤109,2≤l≤r≤36)

Output

For each test case, output the answer in the form of “Case #i: ans” in a seperate line.

Sample Input

3
1 1 2 36
1 982180 10 10
496690841 524639270 5 20

Sample Output

Case #1: 665
Case #2: 1000000
Case #3: 447525746

Source

2017中国大学生程序设计竞赛 - 网络选拔赛

//题意:给出四个整数,L,R,l,r, ∑(L<=i<=R)∑(l<=j<=r) f(i,j) , f(i,j)代表 i 在 j 进制下是否为回文数,是为 k,否则值为 1。

//题解:枚举进制,那么就变为 cal(R,k) - cal(L-1,k) { cal(i,j)表1--i,在k进制下的回文数个数*k+其余数的个数 } 的累加了

计算小于等于一个数的回文数个数并不难,想清楚就好,如果某数前半部分小于该数的前半部分,那一定能构造出来,所以等于时特判一下即可

 # include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <sstream>
# include <set>
# include <cmath>
# include <algorithm>
# pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
# define LL long long
# define pr pair
# define mkp make_pair
# define lowbit(x) ((x)&(-x))
# define PI acos(-1.0)
# define INF 0x3f3f3f3f3f3f3f3f
# define eps 1e-
# define MOD inline int scan() {
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
inline void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
#define MX 500
/**************************/ LL cal(LL x,LL k)
{
int len=;
LL temp=x;
int dat[];
while (temp)
{
dat[len++]=temp%k;
temp/=k;
} LL ans = ,sum = k-,base=;
for (int i=;i<len;i++)
{
ans+=sum-base;
if (i%==)
{
base=sum;
sum=sum*k+k-;
}
}
LL sb=;
for (int i=len-;i>=len/;i--)
sb = sb*k+dat[i];
LL now=sb;
int wei;
if (len%) wei=len/+;
else wei = len/;
for (int i=wei;i<len;i++)
sb = sb*k+dat[i]; if (sb<=x)
ans+=now-base;
else
ans+=now-base-;
return ans*(k-)+x;
} int main()
{
int T = scan();
for (int cnt=;cnt<=T;cnt++)
{
int L,R,l,r;
scanf("%d%d%d%d",&L,&R,&l,&r);
LL ans = ;
for (int i=l;i<=r;i++)
{
ans +=cal(R,i)-cal(L-,i);
}
printf("Case #%d: %lld\n",cnt,ans);
}
return ;
}

Palindrome Function的更多相关文章

  1. HDU - 6156 2017CCPC网络赛 Palindrome Function(数位dp找回文串)

    Palindrome Function As we all know,a palindrome number is the number which reads the same backward a ...

  2. HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛

    普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...

  3. Palindrome Function HDU - 6156(数位dp)

    要求m-n内在l-r进制下的是回文数的总个数. dp[进制][从第j为开始][目前到达第k位] = 总的方案数 dfs枚举目前的到达的位置,这个数开始的位置,进制,前导零,限制条件,然后枚举的时候如果 ...

  4. HDU 6156 Palindrome Function

    http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:$f(n,k)$表示判断n在k进制下是否是回文串,如果是,则返回k,如果不是,则返回1.现在要计算$ ...

  5. HDU 6156 Palindrome Function(数位DP)题解

    思路: 数位dp的操作是dfs+记忆化,我们dp开四维:位置,长度,进制,是否回文.然后每次暴搜记录下每个位置的数字是什么,搜到对称轴另一边需要检查是否符合回文. 终于把友谊赛的题目都补完了...没做 ...

  6. HDU-6156 Palindrome Function(数位DP)

    一.题目 二.思路 1.这是很明显的数位DP: 2.和以往数位DP不同的是,这里带了个进制进来,而以往做是纯十进制下或者纯二进制下做操作.但是,不管多少进制,原理都是一样的: 3.这里有个小坑,题目中 ...

  7. 【数位DP】HDU 6156 Palindrome Function

    http://acm.hdu.edu.cn/showproblem.php?pid=6156 [AC] #include<bits/stdc++.h> using namespace st ...

  8. 【2017中国大学生程序设计竞赛 - 网络选拔赛】Palindrome Function

    [链接]http://acm.hdu.edu.cn/showproblem.php?pid=6156 [题意] 已知函数f(x, k),如果10进制数x在k进制下是个回文数,那么f(x, k)值为k, ...

  9. PPAPI插件开发指南

    转载请注明出处:http://www.cnblogs.com/fangkm/p/4401075.html 前言 插件一直是浏览器的重要组成部分,丰富浏览器的运行能力,实现一些HTML+JS实现不了本地 ...

随机推荐

  1. C++11 Lambda表达式简单解析

    C++11 新增了非常多特性,lambda 表达式是当中之中的一个.假设你想了解的 C++11 完整特性, 建议去http://www.open-std.org/看看新标准! 非常多语言都提供了 la ...

  2. iOS tableView下拉图片放大

    事实上这个效果,本质上就是在你tableView下拉 造成offset时候. 保持你顶部图片的y坐标点还停留在下拉时屏幕的顶点(offset), 而图片的长度变为原始的height长度-(offset ...

  3. Linux 下动态查找磁盘数量方法

    #!/bin/bash ##磁盘数量 Disk=$( fdisk -l |grep 'Disk' |grep 'sd' |awk -F , '{print "%s",substr( ...

  4. js apply和call区别

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  5. JAVA-IO操作,字节-字符转换流

    掌握OutputStreamWriter和InputStreamReader类的作用 一般操作输入输出内容的时候,就需要使用字节或字符流,但是,有些时候,需要将字符流变成字节流形式,或者字节流变成字符 ...

  6. Android创建JSON格式数据

    Android创建JSON格式数据 作为上一篇博客的补充,简单那解说了一下Android创建JSON格式数据的小Demo. 1. 创建JSON格式数据 对于Android创建JSON格式数据.因为An ...

  7. 【MyBatis学习03】原始dao开发方法及其弊端

    上一篇博文总结了一下mybatis的入门,接下来就要开发dao方法了,这篇博文主要总结一下mybatis中原始dao开发的方法,最后并总结一下原始dao开发方法的弊端.mybatis中dao开发应该使 ...

  8. word转pdf

    很多人在工作经常会遇到word转pdf功能,word转pdf还是比较复杂,网上各种包,如python的各种转换包,其实是存在很多问题 的,尤其是对比较复杂的格式,真正的还的是调用组件来转换,这里介绍的 ...

  9. CentOS-6.*安装配置SVN

    安装说明 系统环境:CentOS-6.3 安装方式:yum install (源码安装容易产生版本兼容的问题) 安装软件:系统自动下载SVN软件 检查已安装版本 #检查是否安装了低版本的SVN [ro ...

  10. linux navicat 过期 解决办法

    :~$ cd .navicat:~/.navicat$ rm *.reg:~/.navicat$ rm .update-timestamp:~/.navicat$ rm navicat.crontab ...