Problem I. Increasing or Decreasing MIPT-2016 Pre-Finals Workshop, Taiwan NTU Contest, Sunday, March 27, 2016
题面:
Problem I. Increasing or Decreasing
Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 512 mebibytes
We all like monotonic things, and solved many problems about that like Longest Increasing Subsequence
(LIS). Here is another one which is easier than LIS (in my opinion).
We say an integer is a momo number if its decimal representation is monotonic. For example, 123, 321,
777 and 5566 are momo numbers; But 514, 50216 and 120908 are not.
Please answer m queries. The i-th query is a interval [li; ri], and please calculate the number of momo
numbers in it.
Input
The first line contains an integer m.
Each of the following m lines contains two integers li; ri.
• 1 ≤ m ≤ 105
• 1 ≤ li ≤ ri ≤ 1018
Output
For each query, please output the number of momo numbers in that range.
Example
| standard input | standard output |
| 2 1 100 100 200 |
100 48 |
思路:
数位dp
#include <bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; LL dp[][][];
int num[];
LL dfs(int pos,int s,int pre,int led,int lmt)
{
if(pos<) return !led;
if(!lmt&&~dp[pos][pre][s]) return dp[pos][pre][s];
int mx=lmt?num[pos]:;
LL ans=;
for(int i=;i<=mx;i++)
if(led)
ans+=dfs(pos-,,i,!i&&led,lmt&&i==mx);
else
{
if(s==&&i>pre)
ans+=dfs(pos-,,i,!i&&led,lmt&&i==mx);
else if(s==&&i<pre)
ans+=dfs(pos-,,i,!i&&led,lmt&&i==mx);
else if(s==&&i==pre)
ans+=dfs(pos-,,i,!i&&led,lmt&&i==mx);
else if(s==&&i>=pre)
ans+=dfs(pos-,,i,!i&&led,lmt&&i==mx);
else if(s==&&i<=pre)
ans+=dfs(pos-,,i,!i&&led,lmt&&i==mx);
}
//printf("lm:%d dp[%d][%d][%d]:%I64d\n",lmt,pos,pre,s,ans);
if(!lmt) dp[pos][pre][s]=ans;
return ans;
}
LL go(LL x)
{
if(x<) return ;
int cnt=;
LL ans=;
while(x)
num[++cnt]=x%,x/=;
for(int i=;i<num[cnt];i++)
ans+=dfs(cnt-,,i,!i,);
return ans+dfs(cnt-,,num[cnt],,);
} int main(void)
{
LL m,l,r;
cin>>m;
memset(dp,-,sizeof dp);
while(m--)
{
scanf("%lld%lld",&l,&r);
//printf("%I64d\n",go(r));
printf("%lld\n",go(r)-go(l-));
}
return ;
}
Problem I. Increasing or Decreasing MIPT-2016 Pre-Finals Workshop, Taiwan NTU Contest, Sunday, March 27, 2016的更多相关文章
- 【循环节】【矩阵乘法】MIPT-2016 Pre-Finals Workshop, Taiwan NTU Contest, Sunday, March 27, 2016 Problem F. Fibonacci of Fibonacci
题意:F(n)为斐波那契数列的第n项,问你F(F(n)) mod 20160519的值. 发现有循环节,F(26880696)=0,F(26880697)=1,.... 于是两次矩乘快速幂即可. #i ...
- 【推导】【凸包】MIPT-2016 Pre-Finals Workshop, Taiwan NTU Contest, Sunday, March 27, 2016 Problem D. Drawing Hell
平面上n个点,两个人交替决策,用线段连接两个点,但不能跨越其他点或者已经存在的线段.不能做的人算输,问你谁赢. 实际上,跟两个人的决策无关,n个点将平面三角剖分,只需要算出有几条边即可. 凸包上如果有 ...
- 【Trie】MIPT-2016 Pre-Finals Workshop, Taiwan NTU Contest, Sunday, March 27, 2016 Problem B. Be Friends
题意:一个n个点的完全图,点带权,边权是两端点点权的异或值.问你最小生成树. 一个性质,把所有点按照二进制最高位是否为1划分为2个集合,那么这两个集合间只会有一条边.可以递归处理. 把所有点建成01T ...
- 【分块】MIPT-2016 Pre-Finals Workshop, Taiwan NTU Contest, Sunday, March 27, 2016 Problem A. As Easy As Possible
给你一个字符串,多次区间询问,问你在该区间内最多能有几个easy重复的子序列. 显然如果只有一次询问,从左到右贪心做即可. 分块,预处理任意两块间的答案,不过要把以e a s y开头的四个答案都处理出 ...
- 2016 MIPT Pre-Finals Workshop Taiwan NTU Contest
2016弱校联盟十一专场10.5 传送门 A. As Easy As Possible 假设固定左端点,那么每次都是贪心的匹配\(easy\)这个单词. 从\(l\)开始匹配的单词,将\(y\)的位置 ...
- BNUOJ 52325 Increasing or Decreasing 数位dp
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...
- 即将进行论文答辩的我发现MyEclipse 2016 激活过期害得我又一次把 MyEclipse 2016 给重新激活注册,详细的图文解说激活过程
背景: 在家美滋滋的上着网课享受着因为疫情带来的平静,没想到随着微信.钉钉铃声响起打破了我半年以来的平静的生活:通知我们过完劳动节要进行答辩,由于我的答辩项目是由 MyEclipse 这个工具编写的我 ...
- 【博弈论】【SG函数】【线段树】Petrozavodsk Summer Training Camp 2016 Day 9: AtCoder Japanese Problems Selection, Thursday, September 1, 2016 Problem H. Cups and Beans
一开始有n个杯子,每个杯子里有一些豆子,两个人轮流操作,每次只能将一个豆子移动到其所在杯子之前的某个杯子里,不过可以移动到的范围只有一段区间.问你是否先手必胜. 一个杯子里的豆子全都等价的,因为sg函 ...
- 【线段树】Petrozavodsk Summer Training Camp 2016 Day 6: Warsaw U Contest, XVI Open Cup Onsite, Sunday, August 28, 2016 Problem H. Hay
有一些草,一开始高度都是0,它们的生长速率不同. 给你一些单增的日期,在这些日期要将>b的草的部分都割掉,问你每次割掉的部分有多少. 将草的生长速率从大到小排序,这样每次割掉的是一个后缀,而且不 ...
随机推荐
- sdut 2154:Shopping(第一届山东省省赛原题,水题)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- hdu 4708(暴力+找规律)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 思路:由于N不大,并且我们可以发现通过旋转得到的4个对角线的点的位置关系,以及所要旋转的最小步数 ...
- Proxool线程池的简单实现demo
使用的jar包:ojdbc14.jar proxool-0.9.0.jar commons-logging-1.1.3.jar 代码分为两部分: ProxoolTest.java和proxo ...
- 【BZOJ3417】Poi2013 Tales of seafaring 分层图BFS
[BZOJ3417]Poi2013 Tales of seafaring Description 一个n点m边无向图,边权均为1,有k个询问 每次询问给出(s,t,d),要求回答是否存在一条从s到t的 ...
- 【BZOJ4297】[PA2015]Rozstaw szyn 树形DP
[BZOJ4297][PA2015]Rozstaw szyn Description 给定一棵有n个点,m个叶子节点的树,其中m个叶子节点分别为1到m号点,每个叶子节点有一个权值r[i].你需要给剩下 ...
- kettle中denormalizer(列转行)的使用
转载: 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://sucre.blog.51cto.com/1084905/1434015 ...
- Mac自带Apache和Php
Mac 是默认安装 apache和php,但是需要使用root用户来启用,所以请按照我下面的步骤来: 一.启用root用户1.选取系统偏好设置....2.从显示菜单中,选取“帐户”.3.点按锁图标并使 ...
- [转]通过apk签名使应用程序有系统权限
[转]通过apk签名使应用程序有系统权限 (2013-01-08 13:40:50) 转载▼ 标签: it 分类: Android 出处:http://blog.csdn.net/doom66151/ ...
- datasnap 关于lifecycle的问题
首先DSServerClass的lifecycle属性有Invocation.Server.Session三种模式: 简单叙述一下三点区别: server:datasnap只初始化一个TDSServe ...
- OKEx量化分析报告[2017-12-19]
[分析时间]2017-12-19 09:05 [分析对象]OKEx [有效期限]2017-12-19 09:00:00 — 2017-12-19 09:59:59 [报告内容]DASH_USDT ...