【AC】

 #include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
struct complex
{
double r,i;
complex(double _r = ,double _i = )
{
r = _r; i = _i;
}
complex operator +(const complex &b)
{
return complex(r+b.r,i+b.i);
}
complex operator -(const complex &b)
{
return complex(r-b.r,i-b.i);
}
complex operator *(const complex &b)
{
return complex(r*b.r-i*b.i,r*b.i+i*b.r);
}
};
void change(complex y[],int len)
{
int i,j,k;
for(i = , j = len/;i < len-;i++)
{
if(i < j)swap(y[i],y[j]);
k = len/;
while( j >= k)
{
j -= k;
k /= ;
}
if(j < k)j += k;
}
}
void fft(complex y[],int len,int on)
{
change(y,len);
for(int h = ;h <= len;h <<= )
{
complex wn(cos(-on**PI/h),sin(-on**PI/h));
for(int j = ;j < len;j += h)
{
complex w(,);
for(int k = j;k < j+h/;k++)
{
complex u = y[k];
complex t = w*y[k+h/];
y[k] = u+t;
y[k+h/] = u-t;
w = w*wn;
}
}
}
if(on == -)
for(int i = ;i < len;i++)
y[i].r /= len;
} const int MAXN = ;
complex x1[MAXN];
int a[MAXN/];
long long num[MAXN];//100000*100000会超int
char str[MAXN/];
int main()
{
freopen("duel.in","r",stdin);
freopen("duel.out","w",stdout);
int n=;
scanf("%s",str+);
int ls=strlen(str+);
for(int i=;i<=ls;i++)
{
if(str[i]=='')
{
a[n++]=i;
}
}
memset(num,,sizeof(num));
for(int i = ;i < n;i++)
{
num[a[i]]++;
}
sort(a,a+n);
int len1 = a[n-]+;
int len = ;
while( len < *len1 )len <<= ;
for(int i = ;i < len1;i++)
x1[i] = complex(num[i],);
for(int i = len1;i < len;i++)
x1[i] = complex(,);
fft(x1,len,);
for(int i = ;i < len;i++)
x1[i] = x1[i]*x1[i];
fft(x1,len,-);
for(int i = ;i < len;i++)
num[i] = (long long)(x1[i].r+0.5);
len = *a[n-];
//减掉取两个相同的组合
for(int i = ;i < n;i++)
num[a[i]+a[i]]--;
//选择的无序,除以2
for(int i = ;i <= len;i++)
{
num[i]/=;
}
ll ans=;
for(int i=;i<=len;i++)
{
if(i%!=) continue;
if(str[i/]=='') continue;
ans+=num[i];
}
cout<<ans<<endl;
return ;
}

http://www.cnblogs.com/kuangbin/archive/2013/07/24/3210565.html

【FFT求卷积】Problem D. Duel的更多相关文章

  1. [笔记]ACM笔记 - 利用FFT求卷积(求多项式乘法)

    卷积 给定向量:, 向量和: 数量积(内积.点积): 卷积:,其中 例如: 卷积的最典型的应用就是多项式乘法(多项式乘法就是求卷积).以下就用多项式乘法来描述.举例卷积与DFT. 关于多项式 对于多项 ...

  2. FFT求卷积(多项式乘法)

    FFT求卷积(多项式乘法) 卷积 如果有两个无限序列a和b,那么它们卷积的结果是:\(y_n=\sum_{i=-\infty}^\infty a_ib_{n-i}\).如果a和b是有限序列,a最低的项 ...

  3. CodeForces - 528D Fuzzy Search (FFT求子串匹配)

    题意:求母串中可以匹配模式串的子串的个数,但是每一位i的字符可以左右偏移k个位置. 分析:类似于 UVALive -4671. 用FFT求出每个字符成功匹配的个数.因为字符可以偏移k个单位,先用尺取法 ...

  4. 51nod 算法马拉松 34 Problem D 区间求和2 (FFT加速卷积)

    题目链接  51nod 算法马拉松 34  Problem D 在这个题中$2$这个质数比较特殊,所以我们先特判$2$的情况,然后仅考虑大于等于$3$的奇数即可. 首先考虑任意一个点对$(i, j)$ ...

  5. BZOJ3527 推出卷积公式FFT求值

    BZOJ3527 推出卷积公式FFT求值 传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=3527 题意: \(F_{j}=\sum_{i&l ...

  6. P3803 FFT求多项式系数

    P3803 FFT求多项式系数 传送门:https://www.luogu.org/problemnew/show/P3803 题意: 这是一道FFT模板题,求多项式系数 题解: 对a和b的系数求一个 ...

  7. HDU 1402 A * B Problem Plus (FFT求高精度乘法)

    A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. Gym - 101667H - Rock Paper Scissors FFT 求区间相同个数

    Gym - 101667H:https://vjudge.net/problem/Gym-101667H 参考:https://blog.csdn.net/weixin_37517391/articl ...

  9. (FFT)A+B Problem

    题目链接:https://cn.vjudge.net/contest/280041#problem/B 题目大意:给你n个数,然后让你找满足a[i] + a[j] = a[k] 的情况总数. 具体思路 ...

随机推荐

  1. 洛谷 1164 小A点菜

    题目背景 uim神犇拿到了uoi的ra(镭牌)后,立刻拉着基友小A到了一家……餐馆,很低端的那种. uim指着墙上的价目表(太低级了没有菜单),说:“随便点”. 题目描述 不过uim由于买了一些辅(e ...

  2. codevs 2915 期末考试

    时间限制: 1 s  空间限制: 16000 KB  题目等级 : 黄金 Gold 题目描述 Description 期末考试要来了,某同学正在努力复习. 他要复习N个知识点,每个知识点需要一定的知识 ...

  3. 找出指定文件夹中的所有以txt结尾的文件,包括所有嵌套的子文件夹

    # coding:utf-8 import os, re for i in os.walk('d:'+os.sep):     for txt in i[2]:         try:        ...

  4. 通过例子理解 k8s 架构【转】

    为了帮助大家更好地理解 Kubernetes 架构,我们部署一个应用来演示各个组件之间是如何协作的. 执行命令 kubectl run httpd-app --image=httpd --replic ...

  5. python之文件读写操作(r/r+/rb/w/w+/wb/a/a+/ab)的作用

    'r':只读.该文件必须已存在. 'r+':可读可写.该文件必须已存在,写为追加在文件内容末尾. 'rb':表示以二进制方式读取文件.该文件必须已存在. 'w':只写.打开即默认创建一个新文件,如果文 ...

  6. tomcat性能优化 - 网络抄录

    tomcat默认参数是为开发环境制定,而非适合生产环境,尤其是内存和线程的配置,默认都很低,容易成为性能瓶颈. tomcat内存优化 linux修改TOMCAT_HOME/bin/catalina.s ...

  7. shell脚本,文件里面的英文大小写替换方法。

    [root@localhost wyb]# cat daxiaoxie qweBNMacb eeeDFSmkl svdIOPtyu [root@localhost wyb]# cat daxiaoxi ...

  8. 167. Two Sum II - Input array is sorted@python

    Given an array of integers that is already sorted in ascending order, find two numbers such that the ...

  9. ExtJs如何使用自定义插件动态保存表头配置(隐藏或显示)

    关于保存列表表头的配置,一般我们不需要与后台交互,直接保存在 localStorage 中就能满足常规使用需求(需要浏览器支持). 直接上代码,插件: Ext.define('ux.plugin.Co ...

  10. (9)zabbix创建监控项item

    1. 创建监控项 点击配置(configuration)->主机(Hosts)->在你要配置的主机一栏上点击Items->点击create item.具体看截图,各个参数我都已经标注 ...