[暑假集训--数位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 ...
随机推荐
- python_84_os模块
'os模块:提供对操作系统进行调用的接口' import os print(os.getcwd())#获取当前脚本工作目录,即当前Python脚本工作的目录路径 os.chdir('C:\\Users ...
- PAT (Basic Level) Practise (中文)- 1015. 德才论 (25)
http://www.patest.cn/contests/pat-b-practise/1015 宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡 ...
- 我的offer之路(一)
目录 1.职业规划. 2.刷题. 3.看书. <剑指offer> <数据结构算法与应用:C++语言描述 > <Effective C++> <C与指针> ...
- windows使用批处理bat文件批量打开程序
windows命令行官网教程: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/wind ...
- Linux-CentOS6.9启动流程排错
1 . CentOS6.9启动流程 POST 加电自检,是BIOS功能的一个主要部分.负责完成对CPU.主板.内存.硬盘子系统.显示子系统.串并行接口.键盘.CD-ROM光驱等硬件情况的检测. Boo ...
- python入门:while 循环的基本用法
#!/usr/bin/env python # -*- coding:utf-8 -*- #while 循环的作用 import time while True: ") time.sleep ...
- 代理工具--fiddle
正则匹配 1)前缀为“EXACT:”表示完全匹配:只有match=rules时,才匹配 2)无前缀表示基本搜索,表示搜索到字符串就匹配:只要match中包含了rules的字符串,即可 3)前缀为“NO ...
- Yii2 基于rbac访问控制
Yii2 是一款非常强大的PHP底层框架, 牛b的人都喜欢用它, 有时候你们可能会发现, Yii2 底层处理不是很好, 比如: 每次分页, yii底层都会多统计一次数据的总条数! 那只能说你对它还不 ...
- 谈谈你对Hibernate的理解
答: 1. 面向对象设计的软件内部运行过程可以理解成就是在不断创建各种新对象.建立对象之间的关系,调用对象的方法来改变各个对象的状态和对象消亡的过程,不管程序运行的过程和操作怎么样,本质上都是要得到一 ...
- vscode 实时预览 编辑markdown 插件 Markdown Preview Enhanced
说明地址: https://shd101wyy.github.io/markdown-preview-enhanced/#/zh-cn/?id=markdown-preview-enhanced