求和

题目大意

数据范围


题解

脑筋急转弯可还行.....

我们发现只需要最后枚举个位/xk/xk

因为前面的贡献都是确定的了。

故此我们最后暴力统计一下就好咯。

不知道为啥我组合数一直过不去,暴力求过了呜呜。

代码

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

char *p1, *p2, buf[100000];

#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )

ll rd() {
ll x = 0;
int f = 1;
char c = nc();
while (c < 48) {
if (c == '-')
f = -1;
c = nc();
}
while (c > 47) {
x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
}
return x * f;
} int a[20], cnt, b[20]; ll C[20][20]; void init() {
C[0][0] = 1;
for (int i = 1; i <= 19; i ++ ) {
C[i][0] = 1;
for (int j = 1; j <= i; j ++ ) {
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % 10;
}
}
} inline ll f(ll x) {
cnt = 0;
while (x) {
a[ ++ cnt] = x % 10;
x /= 10;
}
ll mdl = 0;
for (int i = cnt; i >= 2; i -- ) {
(mdl += C[cnt - 1][i - 1] * a[i] % 10) %= 10;
}
return mdl;
} // inline ll f(ll x) {
// cnt = 0;
// for (; x; x /= 10)
// a[cnt ++ ] = x % 10;
// reverse(a, a + cnt);
// while(cnt != 1) {
// int m = 0;
// for (int i = 1; i < cnt; i ++ ) {
// int c = (a[i] + a[i-1]) % 10;
// if(!m && !c) continue;
// b[m ++ ] = c;
// }
// if (!m)
// b[m ++ ] = 0;
// cnt = m;
// for (int i = 0; i < cnt; i ++ )
// a[i] = b[i];
// }
// return a[0];
// } ll calc(ll x) {
if (x < 10ll) {
return (x + 1) * x / 2;
}
ll ans = x / 10 * 45;
ll mdl = f(x / 10 * 10);
// cout << mdl << endl ;
int tmp = x % 10;
for (int i = 0; i <= tmp; i ++ ) {
ans += (mdl + i) % 10;
}
return ans;
} int main() {
int T = rd();
init();
while (T -- ) {
ll l = rd(), r = rd();
printf("%llu\n", calc(r) - calc(l - 1));
}
return 0;
}

小结:真·脑筋急转弯.....

[Comet OJ - Contest #4 D][39D 1584]求和_"数位dp"的更多相关文章

  1. Comet OJ - Contest #2 简要题解

    Comet OJ - Contest #2 简要题解 cometoj A 模拟,复杂度是对数级的. code B 易知\(p\in[l,r]\),且最终的利润关于\(p\)的表达式为\(\frac{( ...

  2. Comet OJ - Contest #2简要题解

    Comet OJ - Contest #2简要题解 前言: 我没有小裙子,我太菜了. A 因自过去而至的残响起舞 https://www.cometoj.com/contest/37/problem/ ...

  3. Comet OJ - Contest #4--前缀和

    原题:Comet OJ - Contest #4-B https://www.cometoj.com/contest/39/problem/B?problem_id=1577传送门 一开始就想着暴力打 ...

  4. Comet OJ - Contest #11 题解&赛后总结

    Solution of Comet OJ - Contest #11 A.eon -Problem designed by Starria- 在模 10 意义下,答案变为最大数的最低位(即原数数位的最 ...

  5. Comet OJ - Contest #8

    Comet OJ - Contest #8 传送门 A.杀手皇后 签到. Code #include <bits/stdc++.h> using namespace std; typede ...

  6. Comet OJ - Contest #13-C2

    Comet OJ - Contest #13-C2 C2-佛御石之钵 -不碎的意志-」(困难版) 又是一道并查集.最近做过的并查集的题貌似蛮多的. 思路 首先考虑,每次处理矩形只考虑从0变成1的点.这 ...

  7. Comet OJ - Contest #13 「火鼠的皮衣 -不焦躁的内心-」

    来源:Comet OJ - Contest #13 芝士相关: 复平面在信息学奥赛中的应用[雾 其实是道 sb 题??? 发现原式貌似十分可二项式定理,然后发现确实如此 我们把 \(a^i\) 替换成 ...

  8. Comet OJ - Contest #13 「佛御石之钵 -不碎的意志-」(hard)

    来源:Comet OJ - Contest #13 一眼并查集,然后发现这题 tmd 要卡常数的说卧槽... 发现这里又要用并查集跳过访问点,又要用并查集维护联通块,于是开俩并查集分别维护就好了 一开 ...

  9. Comet OJ - Contest #5

    Comet OJ - Contest #5 总有一天,我会拿掉给\(dyj\)的小裙子的. A 显然 \(ans = min(cnt_1/3,cnt_4/2,cnt5)\) B 我们可以感性理解一下, ...

随机推荐

  1. Navicat连接虚拟机上的mysql

    刚刚在虚拟主机上安装mysql,  想使用Navicat 操作mysql.  但是连接不上 报错: 2003 - can't connect to MySQL server on '192.168.1 ...

  2. 在 CentOS 7 上安装 RabbitMQ

    RabbitMQ 服务器在安装之前需要安装 erlang. 最新版本的 RabbitMQ 3.8.0 需要 Erlang 21.3 以上的版本支持. 在这里,我们需要在你的 CentOS 中安装 Er ...

  3. eclipse中不能找到dubbo.xsd

    使用dubbo时遇到问题: org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'htt ...

  4. Neo4j 简介 2019

    Neo4j是一个世界领先的开源图形数据库,由 Java 编写.图形数据库也就意味着它的数据并非保存在表或集合中,而是保存为节点以及节点之间的关系. Neo4j 的数据由下面几部分构成: 节点边属性Ne ...

  5. codeforces#1157D. Ehab and the Expected XOR Problem(构造)

    题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...

  6. 【redis 学习系列07】Redis小功能大用处01 慢查询分析以及Redis Shell

    Redis提供了5种数据结构已经足够强大,但除此之外,Redis还提供了诸如慢查询分析.功能强大的Redis Shell.Pipeline.事务与Lua脚本.Bitmaps.HyperLogLog.发 ...

  7. Oracle数据库本地和远程导入、导出

    exp本地导出与imp本地导入 exp命令: 1 exp username/psw@TEST file=d:test.dmp full=y 2 exp username/psw@TEST file=d ...

  8. Nginx-HTTP之静态网页访问流程分析一

    假设访问静态网页的配置如下: worker_processes 1; error_log stderr debug; daemon off; master_process on; events { w ...

  9. FreeMarker学习(常用表达式)

    直接指定值 字符串: "Foo" 或者 'Foo' 或者 "It's \"quoted\"" 或者 'It\'s "quoted& ...

  10. [实战]扩展一个定制的sentinel JdbcDataSource

    Sentinel是今年阿里开源的高可用防护的流量管理框架. git地址:https://github.com/alibaba/Sentinel wiki:https://github.com/alib ...