[暑假集训--数位dp]hdu5898 odd-even number
1 100
110 220
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
1 100
110 220
Case #2: 36
[暑假集训--数位dp]hdu5898 odd-even number的更多相关文章
- [暑假集训--数位dp]hdu3709 Balanced Number
A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...
- [暑假集训--数位dp]LightOj1205 Palindromic Numbers
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- [暑假集训--数位dp]hdu3555 Bomb
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...
- [暑假集训--数位dp]hdu3652 B-number
A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...
- [暑假集训--数位dp]hdu2089 不要62
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍, ...
- [暑假集训--数位dp]hdu5787 K-wolf Number
Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation o ...
- [暑假集训--数位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 ...
- [暑假集训--数位dp]LightOJ1140 How Many Zeroes?
Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...
- [暑假集训--数位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 ...
随机推荐
- QT 调试输出格式
Qt调试输出格式: 1,qDebug() << qPrintable(firstNode.nodeName()) << qPrintable(firstNode.nodeVal ...
- 2018.4.27 Java的Swing常用事件
Swing常用事件 1.Java Swing中处理事件的一般步骤是: (1)新建一个组件(JButton) (2)将该组件添加到面板中(JPanel) (3)注册监听器以监听事件源产生的事件(如Act ...
- 2018.3.26 Linux下学习命令
Linux下的终端文件颜色说明 ---color[=WHEN] 用色彩辨别文件类型 WHEN 可以是'never'.'always'或'auto'其中之一 白色:表示普通文件 蓝色:表示目录 绿色:表 ...
- 线程的sleep方法
- javaweb基础(14)_jsp的原理
一.什么是JSP? JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术. JSP这门技术的最大的特点在于,写jsp就像在写h ...
- java基础—配置环境变量
前言 学习java的第一步就要搭建java的学习环境,首先是要安装JDK,JDK安装好之后,还需要在电脑上配置"JAVA_HOME”."path”."classpath& ...
- db2的定时备份
定时任务: db2.bat db2cmd -i -w db2_backup.bat exit db2_backup.bat db2 connect to TEST db2 force applicat ...
- Oracle 闪回 找回数据的实现方法
Oracle 闪回 找回数据的实现方法 闪回技术是Oracle强大数据库备份恢复机制的一部分,在数据库发生逻辑错误的时候,闪回技术能提供快速且最小损失的恢复.这篇文章主要介绍了Oracle 闪回 找回 ...
- Linux 、AIX环境下查看oracle配置信息(service_name、SID、tnsname)。
SID: echo $ORACLE_SID service_name: sqlplus / as sysdba; show parameter instance_name; show paramete ...
- 【Ubuntu】ubuntu基本操作命令
本文主要是用于记录ubuntu中会使用到的命令,但是有不是特别常用的,用于自己后续查阅使用. 1.查询ubuntu版本信息 方法一: cat /etc/issue 方法二: sudo lsb_rele ...