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

最新文章

  1. SpringMVC+Mybatis+Spring整合
  2. Android项目实战--手机卫士开发系列教程
  3. 纯CSS仿windows系统loading效果
  4. Linux命令-cp
  5. iOS开发——swift精讲&amp;MVC应用实战
  6. 在CDockablePane中嵌入对话框
  7. C#中使用Bogus创建模拟数据
  8. Spring之旅第一篇-初识Spring
  9. Verilog中的reg一定会被综合成寄存器么
  10. [android] 安卓进程优先级&amp;为什么使用服务
  11. java 泛型的通配符和限定
  12. html -- &lt;meta name=&quot;viewport&quot;/&gt;
  13. C#DirectX播放视频
  14. Codeforces Round #426 (Div. 2)A题&amp;&amp;B题&amp;&amp;C题
  15. React的单向数据流与组件间的沟通
  16. Elasticsearch压缩索引——lucene倒排索引本质是列存储+使用嵌套文档可以大幅度提高压缩率
  17. 015-GenericEncodingFilter模板【解决全局乱码】
  18. linux下的cacti安装(centos7)
  19. 关于pdf阅读器的选择
  20. Ajax原生代码

热门文章

  1. ABNF语法
  2. 将数据表中的数据添加到ComboBox控件中
  3. 2018.4.9 Ubuntu install kreogist-mu
  4. MySQL使用INSERT插入多条记录
  5. iOS深拷贝与浅拷贝
  6. poj1654 Area
  7. 【线性基】bzoj2844: albus就是要第一个出场
  8. 【启发式搜索】Codechef March Cook-Off 2018. Maximum Tree Path
  9. 13Shell脚本—编写简单脚本
  10. 使用kickstart + pxe 部署无人值守安装