For a number,if the length of continuous odd digits is even and the length of continuous even digits is odd,we call it odd-even number.Now we want to know the amount of odd-even number between L,R(1<=L<=R<= 9*10^18).
 
Input
First line a t,then t cases.every line contains two integers L and R.
 
Output
Print the output for each case on one line in the format as shown below.
 
Sample Input
2
1 100
110 220
 
Sample Output
Case #1: 29
Case #2: 36

题意是要找x,x当中所有连续的奇数段长度是偶数,连续的偶数段长度是奇数,比如1357246

记一下当前这段是奇数还是偶数,这段已经有多长,有没有前导零。如果有前导零那么0可以也出现奇数次

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<LL,LL>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int len;
LL l,r;
LL f[][][][];
int d[];
inline LL dfs(int now,int dat,int lst,int lead,int fp)
{
if (now==)return (lst&)^(dat&);
if (!fp&&f[now][dat][lst][lead]!=-)return f[now][dat][lst][lead];
LL ans=;
int mx=fp?d[now-]:;
for (int i=;i<=mx;i++)
{
if (i==)
{
if (lead)
{
if (lead&&now-!=)ans+=dfs(now-,,,,fp&&mx==);
else if (lead&&now-==)ans+=dfs(now-,,,,fp&&mx==);
continue;
}
}
if ((i&)==(dat&))ans+=dfs(now-,i,lst+,,fp&&i==mx);
else if ((dat&)^(lst&)||lead)
{
ans+=dfs(now-,i,,,fp&&i==mx);
}
}
if (!fp)f[now][dat][lst][lead]=ans;
return ans;
}
inline LL calc(LL x)
{
if (x==-)return ;
if (x==)return ;
LL xxx=x;
len=;
while (xxx)
{
d[++len]=xxx%;
xxx/=;
}
LL sum=;
sum+=dfs(len,,len==,len!=,d[len]==);
for (LL i=;i<=d[len];i++)
{
sum+=dfs(len,i,,,i==d[len]);
}
return sum;
}
int main()
{
LL T=read();int cnt=;
memset(f,-,sizeof(f));
while (T--)
{
l=read();
r=read();
if (r<l)swap(l,r);
printf("Case #%d: %lld\n",++cnt,calc(r)-calc(l-));
}
}

hdu 5898

For a number,if the length of continuous odd digits is even and the length of continuous even digits is odd,we call it odd-even number.Now we want to know the amount of odd-even number between L,R(1<=L<=R<= 9*10^18).
 
Input
First line a t,then t cases.every line contains two integers L and R.
 
Output
Print the output for each case on one line in the format as shown below.
 
Sample Input
2
1 100
110 220
 
Sample Output
Case #1: 29
Case #2: 36

[暑假集训--数位dp]hdu5898 odd-even number的更多相关文章

  1. [暑假集训--数位dp]hdu3709 Balanced Number

    A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...

  2. [暑假集训--数位dp]LightOj1205 Palindromic Numbers

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  3. [暑假集训--数位dp]hdu3555 Bomb

    The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...

  4. [暑假集训--数位dp]hdu3652 B-number

    A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...

  5. [暑假集训--数位dp]hdu2089 不要62

    杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍, ...

  6. [暑假集训--数位dp]hdu5787 K-wolf Number

    Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation o ...

  7. [暑假集训--数位dp]cf55D Beautiful numbers

    Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer numb ...

  8. [暑假集训--数位dp]LightOJ1140 How Many Zeroes?

    Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...

  9. [暑假集训--数位dp]LightOj1032 Fast Bit Calculations

    A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true&quo ...

随机推荐

  1. pysql用类进行封装

    pyMySQL用类进行封装 class SqlHelper(object): def __init__(self): self.connect() def connect(self): self.co ...

  2. 自行实现一个简易RPC框架

    10分钟写一个RPC框架 1.RpcFramework package com.alibaba.study.rpc.framework; import java.io.ObjectInputStrea ...

  3. Sum All Numbers in a Range-freecodecamp算法题目

    Sum All Numbers in a Range 要求 给你一个包含两个数字的数组.返回这两个数字和它们之间所有数字的和. 最小的数字并非总在最前面. 思路 定义结果变量num 在for循环中,i ...

  4. 【动态规划】bzoj1939: [Croatian2010] Zuma

    隐约记得类似的一道JSOI祖玛……然后好像这题不能够把珠子合并成一段?或许是因为这里珠子碰在一起之后可以不消除? Description 有一行 N 个弹子,每一个都有一个颜色.每次可以让超过 K 个 ...

  5. linux关于软件安装和测试

    软件都是盘上的安装之前确保已挂载完毕 1.安装软件 rpm -ivh httpd-2*   2.修改配置文件 vi /etc/httpd/conf/httpd.conf listen 8888   3 ...

  6. Choose unique values for the 'webAppRootKey' context-param in your web.xml files! 错误的解决

    大意是Log4jConfigListener在获取webapp.root值时,被后一context的值替换掉了,所以要在各个项目的web.xml中配置不同的webAppRootKey值,随即在其中一个 ...

  7. springboot maven 多环境配置

    1.使用Intellij IDEA创建Spring Boot和Maven项目 2.Spring Boot项目下application.yaml(yaml支持中文)或者application.prope ...

  8. destoon 配置文件config.inc.php参数说明

    $CFG['db_host']数据库服务器,可以包括端口号,一般为localhost $CFG['db_user']数据库用户名,一般为root $CFG['db_pass']数据库密码 $CFG[' ...

  9. Applied Nonparametric Statistics-lec9

    Ref:https://onlinecourses.science.psu.edu/stat464/print/book/export/html/12 前面我们考虑的情况是:response是连续的, ...

  10. github FATAL:unable to access 'https://github.com/...: Failed to connect to github.com:443; No error

    今天整理github,初次使用,很多都不懂,所以遇到了克隆失败的问题,研究了大半天,后来..... 打开Git Bash,克隆已有工程到本地: $ git clone https://github.c ...