odd-even number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Problem Description
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;
   dp[i][j][k]三维分别代表位置,当前数奇偶性,个数奇偶性;
   注意前导0的特判;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e5+;
const int N=5e4+;
const int M=N**;
using namespace std;
inline ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
inline ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline void umax(ll &p,ll q){if(p<q)p=q;}
inline void umin(ll &p,ll q){if(p>q)p=q;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,num[],pos,cas;
ll dp[][][],p,q;
ll dfs(int pos,int x,int y,int z,int k)
{
if(pos<)return k&&(x^y)==;
if(z&&k&&dp[pos][x][y]!=-)return dp[pos][x][y];
int now=z?:num[pos],i;
ll ret=;
rep(i,,now)
{
if(k&&(x^(i&))==&&(x^y)==)continue;
if(!i&&!k)ret+=dfs(pos-,x,y,z||i<num[pos],k||i);
else if((i&)==x)ret+=dfs(pos-,x,y^,z||i<num[pos],k||i);
else ret+=dfs(pos-,x^,,z||i<num[pos],k||i);
}
return z&&k?dp[pos][x][y]=ret:ret;
}
ll gao(ll x)
{
pos=;
while(x)num[pos++]=x%,x/=;
return dfs(pos-,,,,);
}
int main()
{
int i,j;
memset(dp,-,sizeof(dp));
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld",&p,&q);
printf("Case #%d: %lld\n",++cas,gao(q)-gao(p-));
}
return ;
}

2016沈阳网络赛 odd-even number的更多相关文章

  1. 2016沈阳网络赛 QSC and Master

    QSC and Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  2. 2018 ICPC 沈阳网络赛预赛 Supreme Number(找规律)

    [传送门]https://nanti.jisuanke.com/t/31452 [题目大意]:给定一个数字(最大可达10100),现在要求不超过它的最大超级质数.超级质数定义:对于一个数,把它看成数字 ...

  3. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

  4. HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)

    题目链接  2016 青岛网络赛  Problem C 题意  给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...

  5. 沈阳网络赛 F - 上下界网络流

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

  6. 沈阳网络赛K-Supreme Number【规律】

    26.89% 1000ms 131072K A prime number (or a prime) is a natural number greater than 11 that cannot be ...

  7. 2016 年沈阳网络赛---QSC and Master(区间DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 Problem Description Every school has some legend ...

  8. HDU 5898 odd-even number(2016沈阳网络选拔赛 数位DP)

    定义DP[pos][pre][odd][even],pos代表当前数位,pre代表前一位的数值,odd代表到前一位连续的奇数个数,even代表到前一位连续偶数个数. odd和even肯定至少有一个为0 ...

  9. HDU 5901 Count primes (2016 acm 沈阳网络赛)

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5901 题意:输入n,输出n以内质数个数 模板题,模板我看不懂,只是存代码用. 官方题解链接:https ...

随机推荐

  1. Flask -- 使用数据库(Sqlite3)、用户注册、登录注销、修改密码

    # 使用sqlite数据库 import sqlite3from contextlib import closing app.config.update( DATABASE = 'my.db', #相 ...

  2. HDU - 2255 奔小康赚大钱(最大带权匹配)

     Problem Description 传说在遥远的地方有一个非常富裕的村落,有一天,村长决定进行制度改革:重新分配房子.这可是一件大事,关系到人民的住房问题啊.村里共有n间房间,刚好有n家老百姓, ...

  3. Android自动测试之Monkey工具

    Monkey工具 前言: 最 近开始研究Android自动化测试方法,对其中的一些工具.方法和框架做了一些简单的整理,其中包括android测试框架.CTS.Monkey. Monkeyrunner. ...

  4. Linux使用期间命令积累

    1.调出终端 Ctrl+Alt+t 2.sudo是linux系统管理指令,是允许系统管理员让普通用户执行一些或者全部的root命令的一个工具,如halt,reboot,su等等. sudo apt-g ...

  5. OLEDB和ODBC的区别

    ODBC(开放数据库互连):是Microsoft引进的一种早期数据库接口技术.它实际上是ADO的前身.早期的数据库连接是非常困难的. 每个数据库的格式都不一样,开发者得对他们所开发的每种数据库的底层A ...

  6. 深入理解HTTP协议(转) 浏览器和服务器如何通信(HTTP协议)

    http协议学习系列 1. 基础概念篇 1.1 介绍 HTTP是Hyper Text Transfer Protocol(超文本传输协议)的缩写.它的发展是万维网协会(World Wide Web C ...

  7. repeat a string in java

    if I want to repeat "hello" four times as a new string-> "hellohellohellohello&quo ...

  8. Linux设置静态IP【转】

    一只小码 2016-08-16 10:32 测试服务器OS: Centos 6.5 x64 本机OS: Ubuntu 14.04 x64 由于Virtualbox当时安装Centos 6.5的时候设置 ...

  9. vb6学习心路

    1.不能加载 'MSCOMCTL.OCX'--继续加载工程吗解决办法:新建一个VB工程,然后按CTRL + T,选中 “Microsoft Windows Common Controls 6.0” 然 ...

  10. 关于ckeditor过滤掉html样式标签之我见

    1.CKEDITOR编辑器属性可以通过修改/ckeditor/config.js文件来控制 //标签过滤默认是开启的,默认会过了<style>样式标签设置为true可关闭过滤config. ...