zoukankan      html  css  js  c++  java
  • JZOJ 2934. 【NOIP2012模拟8.7】字符串函数

    题目大意

    个等长的由大写英文字母构成的字符串 (a)(b),从 (a) 中选择连续子串 (x),从 (b) 中选出连续子串y。
    定义函数 (f_{x,y}) 为满足条件 (x_i=y_i(1<=i<=|x|))(i) 的个数,计算 (f_{x,y}) 的数学期望。((|x|=|y|))

    分析

    其实这题没什么
    如果你读懂了题
    只需要考虑每一位 (i) 的贡献即可

    (Code)

    #include<cstdio>
    #include<string>
    using namespace std;
    typedef long long LL;
    
    const int N = 2e5 + 5;
    int n , f[N][26] , g[N][26];
    LL ans , tot;
    char s1[N] , s2[N];
    
    int main()
    {
    	scanf("%d%s%s" , &n , s1 + 1 , s2 + 1);
    	for(register int i = 1; i <= n; i++)
    	{
    		for(register int j = 0; j < 26; j++) f[i][j] = f[i - 1][j];
    		f[i][s1[i] - 'A'] += i;
    	}
    	for(register int i = n; i; i--)
    	{
    		for(register int j = 0; j < 26; j++) g[i][j] = g[i + 1][j];
    		g[i][s1[i] - 'A'] += n - i + 1;
    	}
    	for(register int i = 1; i <= n; i++)
    	{
    		ans += 1LL * f[i][s2[i] - 'A'] * (n - i + 1) + 1LL * g[i + 1][s2[i] - 'A'] * i;
    		tot += 1LL * i * i;
    	}
    	printf("%lf" , 1.0 * ans / tot);
    }
    
  • 相关阅读:
    HAL 分析
    Ubuntu 11.04 安装后要做的20件事情
    IOStableViewCell自适应高度cell里面放的是UIlable
    IOS支持的字体
    IOS TableView学习资源
    产品与市场
    软件质量与公司盈利
    计算机流派
    让你的软件支持繁体中文
    系统规划设置心得
  • 原文地址:https://www.cnblogs.com/leiyuanze/p/13780161.html
Copyright © 2011-2022 走看看