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. ASP.NET 读数据库绑定到 TreeView 递归方式

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...

  2. 《JS权威指南学习总结--第二章词法结构》

    第二章词法结构 内容要点: 一.注释 1. //表示单行注释 2. /*这里是一段注释*/ 3.一般编辑器里加注释是:选中要加注释的语句,按 ctrl+/ 二.直接量 所谓直接量,就是程序中直接使用的 ...

  3. hdu_3709_Balanced Number(数位DP)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3709 题意:给你一个区间,让你找平衡数的个数 题解:设dp[i][j][k]为前i位以第j位为支撑点的 ...

  4. Java中判断字符串中相同字符的个数

    public static int countStr(String str1, String str2) { int counter=0; if (str1.indexOf(str2) == -1)  ...

  5. Java 反射实例

    实体类:Userpackage com.reflect.model; public class User{ private User(int id, String username, String p ...

  6. inserted触发器,一张表插入数据时,同时向另外一张表插入数据

    有时候,一个服务器上有多个数据库,需要向其中一个数据库的表中插入数据时, 同时向另外一个数据的表里插入数据. 可以利用触发器和同义词(建立同义词的方法省略), 在一个数据库的表里插入数据时,同时向另外 ...

  7. hiho#1128 : 二分·二分查找

    input 1<=n<=1e6 1<=k<=2*1e9 a1 a2 ... an 1<=an<=2*1e9 output k存在则输出k是第几大的数,否则输出-1 ...

  8. ios 获得版本号

    获取iphone的系统信息使用[UIDevice currentDevice],信息如下: [[UIDevice currentDevice] systemName]:系统名称,如iPhone OS ...

  9. combo扩展:禁止手工改变输入框的值

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  10. USB鼠标线序

    鼠标线断了,找了个废弃的手机充电线接上,特记录线序如下: 红————白          白————橙绿————绿黑————蓝