东大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 ...
随机推荐
- SSE图像算法优化系列八:自然饱和度(Vibrance)算法的模拟实现及其SSE优化(附源码,可作为SSE图像入门,Vibrance算法也可用于简单的肤色调整)。
Vibrance这个单词搜索翻译一般振动,抖动或者是响亮.活力,但是官方的词汇里还从来未出现过自然饱和度这个词,也不知道当时的Adobe中文翻译人员怎么会这样处理.但是我们看看PS对这个功能的解释: ...
- 关于ProgressDialog.show抛出android.view.WindowManager$BadTokenException: Unable to add window
下午摆弄ProgressDialog,进入就抛错:android.view.WindowManager$BadTokenException: Unable to add window -- token ...
- linux 目录/sys 解析
今天搞树莓派,遇到/sys这个目录,不太清楚,先对/sys目录知识进行一个整理 首先,对 /sys目录下的各个子目录进行具体说明: /sys下的子目录 内容 /sys/devices 该目录下是全局设 ...
- Beautiful Soup 解决爬虫编码格式问题,Beautiful Soup编码格式
一. 为什么要用解析框架 bs4 我觉得爬虫最难得问题就是编码格式,因为你不知道要爬取目标网站的编码格式,有可能是Unicode,utf-8, ASCII , gbk格式,但是使用Beautiful ...
- 前端学习-jQuery
老师博客:https://www.cnblogs.com/yuanchenqi/articles/6070667.html day43,day44 jquery 中文文档:http://jquery. ...
- Android触摸事件(一)-TouchEventHelper
文件夹 文件夹 概述 关于更新 2016-08-31 2016-06-20 关于单点触摸事件singleTouch 单击的两种方式 关于双击事件 双击事件的检測逻辑 双击事件触发的时机 关于多点触摸事 ...
- python时间模块time详解
在平常的代码中,我们常常需要与时间打交道.在Python中,与时间处理有关的模块就包括:time,datetime以及calendar.这篇文章,主要讲解time模块. 在开始之前,首先要说明这几点: ...
- 数据类型表(DELPHI、C++)
delphi整型数据表 Integer -2147483648..2147483647 signed 32-bit Cardinal 0..4294967295 unsigned 32-bit Sho ...
- Oracle分析函数-keep(dense_rank first/last)
select * from criss_sales where dept_id = 'D02' order by sale_date ; 此时有个新需求,希望查看部门 D02 内,销售记录时间最早,销 ...
- UNION ALL的用法
" ?> -mapper.dtd" > <mapper namespace="com.j1.soa.resource.order.oracle.dao. ...