A serious math problem

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Problem Description

Xiao Jun likes math and he has a serious math question for you to finish.

Define \(F[x]\) to the \(xor\) sum of all digits of \(x\) under the decimal system,for example \(F(1234) = 1\ xor\ 2\ xor\ 3\ xor\ 4 = 4\).

Two numbers \(a,b(a≤b)\) are given,figure out the answer of \(F[a] + F[a+1] + F[a+2]+…+ F[b−2] + F[b−1] + F[b]\) doing a modulo \(10^9+7\).

Input

The first line of the input is a single integer \(T(T<26)\), indicating the number of testcases.

Then \(T\) testcases follow.In each testcase print three lines :

The first line contains one integers \(a\).

The second line contains one integers \(b\).

\(1≤|a|,|b|≤100001\),\(|a|\) means the length of \(a\).

Output

For each test case, output one line "Case #x: y", where x is the case number (starting from 1) and y is the answer.

Sample Input

4

0

1

2

2

1

10

9999

99999

Sample Output

Case #1: 1

Case #2: 2

Case #3: 46

Case #4: 649032

Source

BestCoder Round #55 ($)

这就是数位dp。。。。又想起了当年我作为一个被毒害的小朋友去写windy数的恐惧(哪天再去做一遍233)

我们来简单说一下这道题的做法:

\(dp[i][j]\) 表示\(i\)位数,异或值为\(j\)的数的个数。\((e.g.\ 0-9\ 10 - 99\ 100 - 999\ ......)\)

表示这个转移很暴力~~(代码展示---)

然而数位dp和别的不同的是,dp其实只是你的预处理。。。。你可能还要计数。。。(蒟蒻表示计数比dp难)

需要我们做的操作是求出所有小于等于\(a\)的自然数的异或值的和。而我们预处理的是很多个区间的答案,所以我们还要统计一下。

我们需要把\(a\)这个数给拆成很多个区间。。。

举个栗子:

\(3122=(0~999)+(1000~1999) + (2000~2999) + (3000 ~ 3589)\)

\((3000~3122)=(3000~3099)+(3100~3122)\)

\((3100~3122)=(3100~3109) + (3110~3119) + (3120~3122)\)

按这种方法分解以后,我们就和计数啦~

(注意:代码中可以看出,我们传进去是\(a\),实际上返回的是\(a-1\)的答案,所以适当调整一下~)


#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005, mod = 1e9 + 7;
char a[maxn], b[maxn];
int dp[maxn][20], ans[20];
int cas, last, qwe; inline void prepare()
{
dp[0][0] = 1;
for(int i = 0; i <= 9; ++i) dp[1][i] = 1;
for(int i = 2; i < maxn; ++i)
for(int j = 0; j < 10; ++j)
for(int k = 0; k <= 15; ++k)
dp[i][j ^ k] += dp[i - 1][k], dp[i][j ^ k] %= mod;
} inline int workk(char * str)
{
int len = strlen(str + 1); int pre = 0; int ret = 0;
memset(ans, 0, sizeof(ans));
for(int i = 1; i <= len; ++i)
{
int num = str[i] - '0';
for(int j = 0; j < num; ++j)
{
for(int k = 0; k <= 15; ++k)
{
ans[pre ^ j ^ k] += dp[len - i][k];
ans[pre ^ j ^ k] %= mod;
}
}
pre ^= num;
}
for(int i = 1; i <= 15; ++i) ret = (ret + (long long)i * ans[i]) % mod;
return ret;
} int main()
{
prepare();
int t; scanf("%d", &t);
while(t--)
{
cas++; qwe = 0; last = 0;
scanf("%s", a + 1); scanf("%s", b + 1); int p = strlen(b + 1);
for (int i = 1; i <= p; i++) last ^= (b[i] - '0');
qwe = (workk(b) - workk(a) + mod) % mod;
qwe = (qwe + last) % mod;
printf("Case #%d: %d\n", cas, qwe);
}
return 0;
}

hdu 5435 A serious math problem的更多相关文章

  1. HDU 5055 Bob and math problem(结构体)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been think ...

  2. HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...

  3. hdu 1757 A Simple Math Problem (乘法矩阵)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. HDU 5615 Jam's math problem

    Jam's math problem Problem Description Jam has a math problem. He just learned factorization.He is t ...

  5. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

  6. HDU 1757 A Simple Math Problem(矩阵)

    A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...

  7. HDU 1757 A Simple Math Problem (矩阵乘法)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. hdu 5974 A Simple Math Problem

    A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  9. HDU 1757 A Simple Math Problem(矩阵高速幂)

    题目地址:HDU 1757 最终会构造矩阵了.事实上也不难,仅仅怪自己笨..= =! f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 ...

随机推荐

  1. ToolStripComboBox 绑定数据

    //添加ComboBox tcbbQueryCondition.ComboBox.DataSource = RelationalOperators.GetAllOperators(); tcbbQue ...

  2. 【转载】windows 开启 nginx 监听80 端口 以及 禁用 http 服务后,无法重启 HTTP 服务,提示 系统错误 123,文件目录、卷标出错

    https://www.cnblogs.com/TianyuSu/p/9509873.html location / { proxy_set_header Host $Host; proxy_set_ ...

  3. java插件提示安全设定高,不能加载解决方法

    当不可信小应用程序或应用程序在 Web 浏览器中运行时,我应当如何控制? 本文适用于: Java 版本: 7.0, 8.0 通过 Java 控制面板设置安全级别 在 Java 控制面板中,单击 Sec ...

  4. BZOJ4386 [POI2015]Wycieczki 矩阵+倍增

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4386 题解 一眼就可以看出来是邻接矩阵快速幂. 可是这里的边权不为 \(1\).不过可以发现, ...

  5. jQuery-Ajax请求Json数据并加载在前端页面,附视频教程讲解!

    Ajax技术应用广泛,这种异步加载技术,无需刷新网页即可更新网站内容,全局或者局部均可,所以大家应该学会这种技巧,把技术用上来. 创建demo.json文件,用来做数据源: {     "t ...

  6. JDK1.8新特性之Stream类初识

    JDK1.8新特性之Stream类初识 import java.util.Arrays; import java.util.List; import java.util.Optional; impor ...

  7. Vue-Cli 安装使用 moment.js

    1.npm install moment -- save 2.main.js 引入moment //定义全局 时间过滤器 S import Moment from 'moment'; Vue.filt ...

  8. 2019 GNTC 阿里云参会分享:云原生SDWAN网络2.0 一站式上云服务

    本次10/22-24 南京2019 GNTC大会上,阿里云网络云原生SDWAN网络2.0 由于独特的云原生定位.创新的解决方案,及成熟的应用案例.行业用户,获得行业媒体C114中国通信网.产业专家高度 ...

  9. Java Web学习总结(10)学习总结-EL表达式

    一,EL 表达式概述(EL主要从域中取数据) EL(Express Lanuage)表达式可以嵌入在jsp页面内部,减少jsp脚本的编写,EL出现的目的是要替代jsp页面中脚本的编写. 二,EL从域中 ...

  10. Git的安装及配置

    1.Git Git 是一个开源的分布式版本管理工具,可以在你电脑不联网的情况下,只在本地使用的一个版本管理工具,其作用就是可以让你更好的管理你的程序.在你每次的修改代码并提交后,Git 都会将这些记录 ...