东大oj1155 等凹函数
定义一种数字称为等凹数字,即从高位到低位,每一位的数字先递减再递增,且该数是一个回文数,即从左读到右与从右读到左是一样的,仅形成一个等凹峰,如543212345,5544334455是合法的等凹数字,543212346,123321不是等凹数字。现在问你[L,R]中有多少等凹数字呢?L,R<=1e18(小于等于2位的无凹峰)
第一行一个整数T,表示有T组数据,T <= 110.
接下来的每行包含两个用空格分开的整数L R,保证L,R<=1e18.
对于每组输入,在一行输出一个整数,代表[L,R]中等凹数字的个数。
1 100
666 666666
356
#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 等凹函数的更多相关文章
- 东大OJ-Max Area
1034: Max Area 时间限制: 1 Sec 内存限制: 128 MB 提交: 40 解决: 6 [提交][状态][讨论版] 题目描述 又是这道题,请不要惊讶,也许你已经见过了,那就请你再 ...
- 开学&东大一周游记
明天就要离开生活但并没有学到多少东西的东大了,不舍,这是真的,因为真的是没学到多少就要走了.但是终归是有收获的,比如感受到了舍长这样的大牛的学习态度,东大的浴池真的很棒,我很感激吉大的伙食诸如此类.感 ...
- 东大oj-1511: Caoshen like math
Worfzyq likes Permutation problems.Caoshen and Mengjuju are expert at these problems . They have n c ...
- 东大OJ-1588: Routing Table
题目描述 In the computer network, a Router is a device which finds an optimal way to transmit the datagr ...
- 东大oj-1591 Circle of friends
题目描述 Nowadays, "Circle of Friends" is a very popular social networking platform in WeChat. ...
- 东大OJ-1544: GG的战争法则
题目描述 你在桥上看风景 看风景的人在楼上看你 明月装饰了你的窗子 你装饰了我的梦 这是GG在长坂坡发出的感叹. 三年前GG莫名的穿越到了三国时期,在这三年里他看尽了各种杀戮,心里早已麻木.GG他渴望 ...
- 东大OJ-最大子序列问题的变形
1302: 最大子序列 时间限制: 1 Sec 内存限制: 128 MB 提交: 224 解决: 54 [提交][状态][讨论版] 题目描述 给定一个N个整数组成的序列,整数有正有负,找出两段不重 ...
- 东大OJ-双塔问题
1212: VIJOS-P1037 时间限制: 0 Sec 内存限制: 128 MB 提交: 58 解决: 19 [提交][状态][讨论版] 题目描述 2001年9月11日,一场突 ...
- 东大OJ-Prim算法
1222: Sweep the snow 时间限制: 1 Sec 内存限制: 128 MB 提交: 28 解决: 18 [提交][状态][讨论版] 题目描述 After the big big s ...
随机推荐
- WPF双向数据绑定总结
参考官方:https://docs.microsoft.com/zh-cn/dotnet/framework/wpf/data/data-binding-wpf 实例程序:https://files. ...
- ionic BUILD FAILED
BUILD FAILED Total time: 24.572 secs FAILURE: Build failed with an exception. What went wrong: Execu ...
- Python String Formatting Best Practices
https://imliyan.com/blogs/article/Python3.6%E6%96%B0%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%A0%BC%E5 ...
- Linux远程执行shell命令
Linux远程执行shell命令 在Linux系统中,我们经常想在A机器上,执行B机器上的SHELL命令. 下面这种方案,是一种流行可靠的方案. 1.SSH无密码登录 # 本地服务器执行(A机器) ...
- Pinterest凭什么拥有那么多用户:机器学习是答案
目前,Pinterest月平均活跃用户量达到1亿,这家以图片为主的公司是如何留住用户并盈利的呢?Pinterest的主要目标是向用户推荐相关的图片或内容,推荐的内容足够精确才能提高用户黏性.近期,&l ...
- MySQL技术内幕读书笔记(一)——Mysql体系结构和存储引擎
目录 MySQL体系结构和存储引擎 定义数据库和实例 MYSQL体系结构 MYSQL存储引擎 MySQL体系结构和存储引擎 定义数据库和实例 数据库:物理操作系统文件或者其他形式文件类型的结合.在MY ...
- cpu使用过高的一次处理方法
1.top查看使用情况 2.查看mysql里的线程,观察是否有长期运行或阻塞的sql: show full processlist 原因找到,处理方法,添加索引,搞定
- mongodb 复杂查询之 本表 join
mongdb 的数据介绍: 系统有多个用户,contractId 代表用户Id,其中 serialno 也是一种 id,代表该客户登录系统的编号,该 contractId 每次登录系统都会产生不同 ...
- Asp.Net WebApi上传图片
webapi using System; using System.Collections; using System.Collections.Generic; using System.Diagno ...
- 并发框架Disruptor译文
Martin Fowler在自己网站上写了一篇LMAX架构的文章,在文章中他介绍了LMAX是一种新型零售金融交易平台,它能够以很低的延迟产生大量交易.这个系统是建立在JVM平台上,其核心是一个业务逻辑 ...