https://codeforc.es/problemset/problem/1195/D2

很明显可以看出,任意一个长度为\(l_1\)的数串\(s_1\)和任意一个长度为\(l_2\)的数串\(s_2\)在\(f(s_1,s_2)\)中每个位的贡献的位数是一样的。稍微推一推可以知道,\(calcx\_ijk\)和\(calcy\_ijk\)的公式。然后暴力统计一波各个长度的数串有几个就可以了。小心溢出。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; ll a[100005];
ll di[100005][11];
int cntws[11]; ll gx[11][11][11];
ll gy[11][11][11]; const ll mod = 998244353; int ws(ll x) {
int cnt = 0;
while(x) {
//cout<<x<<" ";
cnt++;
x /= 10;
//cout<<cnt<<endl;
}
return cnt;
} ll ans; ll calc_base(int i,int k){
ll res=0;
for(int j=1;j<=10;j++){
res=(res+1ll*cntws[j]*gx[i][j][k]%mod)%mod;
res=(res+1ll*cntws[j]*gy[i][j][k]%mod)%mod;
}
//cout<<"i="<<i<<" k="<<k<<" res="<<res<<endl;
return res;
} ll calc(ll x) {
ll res = 0;
int i=ws(x);
for(int k=1;k<=i;k++){
ll r = x%10;
res = (res + calc_base(i,k)* r % mod) % mod;
x /= 10;
}
return res % mod;
} ll p10[23]; ll calc_ijk(int i, int j, int k) {
if(k <= j) {
return p10[k * 2];
} else {
return p10[j + k];
}
} ll calc_ijk2(int i, int j, int k) {
if(k <= j) {
return p10[k * 2 - 1];
} else {
return p10[j + k];
}
} void init_gx() {
memset(gx, 0, sizeof(gx));
//gx[i][j][k]i是x,j是y的时候,导致i的第k位贡献的位数
//gy[i][j][k]i是x,j是y的时候,导致j的第k位贡献的位数
for(int i = 1; i <= 10; i++) {
for(int j = 1; j <= 10; j++) {
for(int k = 1; k <= i; k++) {
gx[i][j][k] = calc_ijk(i, j, k);
}
}
}
memset(gy, 0, sizeof(gy));
//gx[i][j]i是x,j是y的时候,导致i贡献的位数
//gy[i][j]i是x,j是y的时候,导致j贡献的位数
for(int i = 1; i <= 10; i++) {
for(int j = 1; j <= 10; j++) {
for(int k = 1; k <= i; k++) {
gy[i][j][k] = calc_ijk2(i, j, k);
}
}
}
} int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
//freopen("Yinku.out", "w", stdout);
#endif // Yinku
p10[1] = 1;
for(int i = 2; i <= 21; i++) {
p10[i] = p10[i - 1] * 10ll % mod;
//cout<<p10[i]<<endl;
}
int n;
init_gx();
for(int i = 1; i <= 2; i++) {
for(int j = 1; j <= 2; j++) {
for(int k = 1; k <= i; k++) {
gx[i][j][k] %= mod;
gy[i][j][k] %= mod;
//printf("%lld ",gx[i][j][k]);
//printf("%lld",gy[i][j][k]);
}
//printf("\n");
}
//printf("\n");
}
while(~scanf("%d", &n)) {
memset(cntws, 0, sizeof(cntws));
for(int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
cntws[ws(a[i])]++;
//cout<<ws(a[i])<<endl;
}
/*for(int i = 1; i <= 10; ++i) {
//cout<<cntws[i]<<endl;
}*/
ans = 0;
for(int i = 1; i <= n; i++) {
ans = (ans + calc(a[i])) % mod;
//printf("ans=%lld\n", ans % mod);
}
printf("%lld\n", ans % mod);
}
}

发现其实可以缩写成下面的形式:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; const int mod = 998244353; int a[100005];
int lena[100005];
int cntlen[11]; int g[11][11][11]; int len(int x) {
int cnt = 0;
while(x) {
cnt++;
x /= 10;
}
return cnt;
} ll ans; ll calc_base(int i, int k) {
ll res = 0;
for(int j = 1; j <= 10; j++)
res = (res + 1ll * g[i][j][k] * cntlen[j] % mod) % mod;
return res;
} ll calc(int x, int lenx) {
ll res = 0;
for(int k = 1; k <= lenx; k++) {
int r = x % 10;
res = (res + calc_base(lenx, k) * r % mod) % mod;
x /= 10;
}
return res % mod;
} int p10[21]; void init_g() {
memset(g, 0, sizeof(g));
//g[i][j][k]是两个数分别是i位,j位时候,导致长度为i的第k位发生的贡献
for(int i = 1; i <= 10; i++)
for(int j = 1; j <= 10; j++)
for(int k = 1; k <= i; k++)
g[i][j][k] = (p10[k + ((k <= j) ? k : j)] + p10[k + ((k <= j) ? (k - 1) : j)]) % mod;
} void init_p10() {
p10[1] = 1;
for(int i = 2; i <= 20; i++) {
p10[i] = p10[i - 1] * 10ll % mod;
}
} int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
//freopen("Yinku.out", "w", stdout);
#endif // Yinku
init_p10();
init_g();
int n;
while(~scanf("%d", &n)) {
memset(cntlen, 0, sizeof(cntlen));
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
lena[i] = len(a[i]);
cntlen[lena[i]]++;;
}
ans = 0;
for(int i = 1; i <= n; i++) {
ans = (ans + calc(a[i], lena[i])) % mod;
}
printf("%lld\n", ans);
}
}

Codeforces - 1195D2 - Submarine in the Rybinsk Sea (hard edition) - 组合数学的更多相关文章

  1. Codeforces - 1195D1 - Submarine in the Rybinsk Sea (easy edition) - 水题

    https://codeforc.es/contest/1195/problem/D1 给\(n\)个等长的十进制数串,定义操作\(f(x,y)\)的结果是"从\(y\)的末尾开始一个一个交 ...

  2. Codeforces Round #574 (Div. 2) D2. Submarine in the Rybinsk Sea (hard edition) 【计算贡献】

    一.题目 D2. Submarine in the Rybinsk Sea (hard edition) 二.分析 相比于简单版本,它的复杂地方在于对于不同长度,可能对每个点的贡献可能是有差异的. 但 ...

  3. Codeforces Round #574 (Div. 2) D1. Submarine in the Rybinsk Sea (easy edition) 【计算贡献】

    一.题目 D1. Submarine in the Rybinsk Sea (easy edition) 二.分析 简单版本的话,因为给定的a的长度都是定的,那么我们就无需去考虑其他的,只用计算ai的 ...

  4. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...

  5. codeforces 1195D2-Submarine in the Rybinsk Sea

    传送门:QAQQAQ 题意:自己看 思路:就是一个类似于数位DP的东西... 统计a[i]数位分解的数在每一位出现的个数,即分两种讨论: 1.位数小于当前j,则j会出现在q+i,而且计算顺序互换会计算 ...

  6. Codeforces Round #302 (Div. 2) B. Sea and Islands 构造

    B. Sea and Islands Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/p ...

  7. Codeforces Round #380 (Div. 2)/729D Sea Battle 思维题

    Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the ...

  8. Codeforces Round #541 (Div. 2) A.Sea Battle

    链接:https://codeforces.com/contest/1131/problem/A 题意: 给两个矩形,一个再上一个在下,求两个矩形合并的周围一圈的面积. 思路: 因为存在下面矩形宽度大 ...

  9. Codeforces Round #258 (Div. 2) D. Count Good Substrings —— 组合数学

    题目链接:http://codeforces.com/problemset/problem/451/D D. Count Good Substrings time limit per test 2 s ...

随机推荐

  1. 下载-MS SQL Server 2005(大全版)含开发人员版、企业版、标准版【转】

    中文名称:微软SQL Server 2005 英文名称:MS SQL Server 2005资源类型:ISO版本:开发人员版.企业版.标准版发行时间:2006年制作发行:微软公司地区:大陆语言:普通话 ...

  2. TensorFlow——CNN卷积神经网络处理Mnist数据集

    CNN卷积神经网络处理Mnist数据集 CNN模型结构: 输入层:Mnist数据集(28*28) 第一层卷积:感受视野5*5,步长为1,卷积核:32个 第一层池化:池化视野2*2,步长为2 第二层卷积 ...

  3. 21eval 函数

    eval() 函数十分强大 ---- 将字符串 当成 有效的表达式 来求职 并 返回计算结果 # 基本的数学计算 # 字符串重复 print(eval("'*' * 5")) # ...

  4. fiddler 手机抓包,CS端抓包 使用记录

    1.允许远程连接 2.忽略https证书错误 3.设置代理 4.重启fiddle 5.PC客户端抓包分工具FIddler+Proxifer https://blog.csdn.net/sunbo_cs ...

  5. maven 常用插件 拷贝依赖 拷贝jar包 查看属性 环境变量

    1 maven编译后希望将生产的jar包拷贝到指定目录 在pom中配置maven插件 maven-antrun-plugin <build > <plugins> <pl ...

  6. JFreeChart使用

    最近项目需要做图形分析,就想到了使用JFreeChart,之前也没有使用过,就现学先用吧.本文主要记录一些主要的代码及学习使用过程. 使用JFreeChart步骤: 一.下载JFreeChart.ja ...

  7. 【leetcode】1038. Binary Search Tree to Greater Sum Tree

    题目如下: Given the root of a binary search tree with distinct values, modify it so that every node has ...

  8. 本页面用来演示如何通过JS SDK,创建完整的QQ登录流程,并调用openapi接口

    QQ登录将用户信息存储在cookie中,命名为__qc__k ,请不要占用 __qc__k : 1) :: 在页面顶部引入JS SDK库: 将“js?”后面的appid参数(示例代码中的:100229 ...

  9. (3.1)狄泰软件学院C++课程学习剖析二

    深度剖析C++第二部分 1.通过对象名能够访问public成员变量.每个对象的成员变量都是专属的,成员变量不能够在对象之间共享. 2.需求:统计在程序运行期间某个类的对象数目,保证程序的安全性(不能使 ...

  10. 破解Revealapp的试用时间限制

    转载自:http://jingwei6.me/2014/02/28/reveal_crack.html Revealapp作为分析iOS app UI结构的利器,还是非常称手的,89刀的价格也是物有所 ...