Problem Description

定义一种数字称为等凹数字,即从高位到低位,每一位的数字先递减再递增,且该数是一个回文数,即从左读到右与从右读到左是一样的,仅形成一个等凹峰,如543212345,5544334455是合法的等凹数字,543212346,123321不是等凹数字。现在问你[L,R]中有多少等凹数字呢?L,R<=1e18(小于等于2位的无凹峰)

Input

第一行一个整数T,表示有T组数据,T <= 110.

接下来的每行包含两个用空格分开的整数L R,保证L,R<=1e18.

Output

对于每组输入,在一行输出一个整数,代表[L,R]中等凹数字的个数。

Sample Input
2
1 100
666 666666
Sample Output
0
356
 
没有dfs算不了的问题,如果有,那就用天河一号去dfs(误)
每次都从L到R循环挨个验证肯定TLE,所以用了递归去构造回文数,每次尝试填一个数字,且要求小于等于上一个数字,填完之后给他左右对称过去,这样就生成了一个等凹数字,把他丢到答案数组里面。
对称有两种,比如54322345, 5432345,所以写了两个create分别生成这两种等凹。
有意思的是,从1到1e18,有184574个等凹数。
#include<cstdio>
#include<algorithm>
using std:: sort;
long long res[], NUM = ;
int temp[] = {};
void create(int n)//
{
long long ans = ;
for(int i = n; i <= *n-; i++)
temp[i] = temp[*n-i];
for(int i = ; i <= *n-; i++)
{
ans *= ;
ans += temp[i];
}
res[NUM++] = ans;
}
void create2(int n)
{
long long ans = ;
for(int i = n+; i <= *n; i++)
temp[i]= temp[*n+-i];
for(int i = ; i <= *n; i++)
{
ans *= ;
ans += temp[i];
}
res[NUM++] = ans;
}
void dfs(int cur, int n)//create n down words 1 : n
{
if(cur == n+)
{
int ok = , cmp = temp[];
for(int i = ; i <= n; i++)//平 胸 禁 止(反正也没人看到(误))
if(temp[i] != cmp)
ok = ;
if(ok)
{
create(n);
create2(n);
}
return;
}
for(int i = ; i <= ; i++)
{
if(i <= temp[cur-])
{
temp[cur] = i;
dfs(cur+, n);
}
}
}
void test()
{
for(int i = ; i < NUM; i++)
printf("%lld ", res[i]);
} int main()
{
for(int i= ; i <= ; i++)
dfs(, i);
sort(res, res+NUM);
//test();
int t;
scanf("%d", &t);
while(t--)
{
long long L, R, l, r;
scanf("%lld%lld", &L, &R);
for(int i = ; i < NUM; i++)
if(res[i] >= L)
{
l = i;
break;
}
for(int i = NUM-; i >= ; i--)
if(res[i] <= R)
{
r = i;
break;
}
printf("%lld\n", r-l+);
}
return ;
}
 

东大oj1155 等凹函数的更多相关文章

  1. 东大OJ-Max Area

    1034: Max Area 时间限制: 1 Sec  内存限制: 128 MB 提交: 40  解决: 6 [提交][状态][讨论版] 题目描述 又是这道题,请不要惊讶,也许你已经见过了,那就请你再 ...

  2. 开学&东大一周游记

    明天就要离开生活但并没有学到多少东西的东大了,不舍,这是真的,因为真的是没学到多少就要走了.但是终归是有收获的,比如感受到了舍长这样的大牛的学习态度,东大的浴池真的很棒,我很感激吉大的伙食诸如此类.感 ...

  3. 东大oj-1511: Caoshen like math

    Worfzyq likes Permutation problems.Caoshen and Mengjuju are expert at these problems . They have n c ...

  4. 东大OJ-1588: Routing Table

    题目描述 In the computer network, a Router is a device which finds an optimal way to transmit the datagr ...

  5. 东大oj-1591 Circle of friends

    题目描述 Nowadays, "Circle of Friends" is a very popular social networking platform in WeChat. ...

  6. 东大OJ-1544: GG的战争法则

    题目描述 你在桥上看风景 看风景的人在楼上看你 明月装饰了你的窗子 你装饰了我的梦 这是GG在长坂坡发出的感叹. 三年前GG莫名的穿越到了三国时期,在这三年里他看尽了各种杀戮,心里早已麻木.GG他渴望 ...

  7. 东大OJ-最大子序列问题的变形

    1302: 最大子序列 时间限制: 1 Sec  内存限制: 128 MB 提交: 224  解决: 54 [提交][状态][讨论版] 题目描述 给定一个N个整数组成的序列,整数有正有负,找出两段不重 ...

  8. 东大OJ-双塔问题

    1212: VIJOS-P1037 时间限制: 0 Sec  内存限制: 128 MB 提交: 58  解决: 19 [提交][状态][讨论版] 题目描述         2001年9月11日,一场突 ...

  9. 东大OJ-Prim算法

    1222: Sweep the snow 时间限制: 1 Sec  内存限制: 128 MB 提交: 28  解决: 18 [提交][状态][讨论版] 题目描述 After the big big s ...

随机推荐

  1. Navicat http 通道增加验证

    ntunnel_mysql.php 中增加 function check() { if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authen ...

  2. 【C#】C#线程_计算限制的异步操作

    目录结构: contents structure [+] 线程池简介 执行上下文(Execution Context) CancelTokenSource的使用 ThreadPool Task和Tas ...

  3. Huginn及环境搭建

    博客搬迁至https://blog.wangjiegulu.com RSS订阅:https://blog.wangjiegulu.com/feed.xml Huginn 及环境搭建 什么是 Hugin ...

  4. Atitit s2018.5 s5 doc list on com pc.docx  Acc 112237553.docx Acc baidu netdisk.docx Acc csdn 18821766710 attilax main num.docx Atiitt put post 工具 开发工具dev tool test.docx Atiitt 腾讯图像分类相册管家.docx

    Atitit s2018.5 s5  doc list on com pc.docx  Acc  112237553.docx Acc baidu netdisk.docx Acc csdn 1882 ...

  5. Renascence架构介绍——文件夹

    这一系列文章是为个人项目作一个介绍.有兴趣的朋友能够关注一下. https://github.com/jxt1234/Renascence 先写个文件夹.以后按文件夹更新 1.自己主动编程体系设想 2 ...

  6. 无法加载协定为“ServiceReference1.xxxxxx”的终结点配置部分,因为找到了该协定的多个终结点配置。请按名称指示首选的终结点配置部分。

    原因是在web.config 文件中多次引用了“添加外部引用” <system.serviceModel> <bindings> <basicHttpBinding> ...

  7. Jet.com

    Jet.com是一家电商startup,总部在最爱的小城市Hoboken.目前是类似Amazon的一个网站,后台用F#来做Micro Services,服务器都在Azure和AWS上.人员配置年轻聪明 ...

  8. oozie调度sqoop Job 数据库密码无法保存

    问题描述 通过oozie调度sqoop作业时,需要输入数据库作业密码,但在sqoop元数据服务配置密码后,过一段时间会失效. 解决方法 将数据库密码写入HDFS文件,通过配置Sqoop job,实现传 ...

  9. 第四百零四节,python网站第三方登录,social-auth-app-django模块,

    第四百零四节,python网站第三方登录,social-auth-app-django模块, social-auth-app-django模块是专门用于Django的第三方登录OAuth2协议模块 目 ...

  10. tensorflow 调试tfdbg

    1.执行pip install pyreadline 安装pyreadline 2.修改对应代码如下 with tf.Session() as sess: sess.run(tf.global_var ...