题目链接:HDU-6061

题意:给定f(x),求f(x-A)各项系数。

思路:推导公式有如下结论:

然后用NTT解决即可。

代码:

#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long LL;
const LL MAXN=;
const LL MOD=; // NTT
// O(nlogn)
// Verified!
const LL P = MOD;
const LL G = ;
const LL NUM = ; LL wn[NUM];
LL A[MAXN], B[MAXN]; LL quick_mod(LL a, LL b, LL m)
{
LL ans = ;
a %= m;
while(b)
{
if(b & )
{
ans = ans * a % m;
b--;
}
b >>= ;
a = a * a % m;
}
return ans;
} void GetWn()
{
for(LL i=; i<NUM; i++)
{
LL t = << i;
wn[i] = quick_mod(G, (P - ) / t, P);
}
} void Prepare(char A[], char B[], LL a[], LL b[], LL &len)
{
len = ;
LL len_A = strlen(A);
LL len_B = strlen(B);
while(len <= * len_A || len <= * len_B) len <<= ;
for(LL i=; i<len_A; i++)
A[len - - i] = A[len_A - - i];
for(LL i=; i<len - len_A; i++)
A[i] = '';
for(LL i=; i<len_B; i++)
B[len - - i] = B[len_B - - i];
for(LL i=; i<len - len_B; i++)
B[i] = '';
for(LL i=; i<len; i++)
a[len - - i] = A[i] - '';
for(LL i=; i<len; i++)
b[len - - i] = B[i] - '';
} void Rader(LL a[], LL len)
{
LL j = len >> ;
for(LL i=; i<len-; i++)
{
if(i < j) swap(a[i], a[j]);
LL k = len >> ;
while(j >= k)
{
j -= k;
k >>= ;
}
if(j < k) j += k;
}
} void NTT(LL a[], LL len, LL on)
{
Rader(a, len);
LL id = ;
for(LL h = ; h <= len; h <<= )
{
id++;
for(LL j = ; j < len; j += h)
{
LL w = ;
for(LL k = j; k < j + h / ; k++)
{
LL u = a[k] % P;
LL t = w * (a[k + h / ] % P) % P;
a[k] = (u + t) % P;
a[k + h / ] = ((u - t) % P + P) % P;
w = w * wn[id] % P;
}
}
}
if(on == -)
{
for(LL i = ; i < len / ; i++)
swap(a[i], a[len - i]);
LL Inv = quick_mod(len, P - , P);
for(LL i = ; i < len; i++)
a[i] = a[i] % P * Inv % P;
}
} void Conv(LL a[], LL b[], LL n)
{
NTT(a, n, );
NTT(b, n, );
for(LL i = ; i < n; i++)
a[i] = a[i] * b[i] % P;
NTT(a, n, -);
} // 快速幂
// 求x^n%mod
// Verified!
LL powMod(LL x,LL n,LL mod)
{
LL res=;
while(n>)
{
if(n&) res=res*x % mod;
x=x*x % mod;
n>>=;
}
return res;
}
// 求逆元
// a和m应该互质
// 根据欧拉定理:a的逆即a^(phi(m)-1)
LL inv(LL a,LL m)
{
return powMod(a,m-,m);
// return powMod(a,eularPhi(m)-1,m);
}
LL mi[MAXN],invsum[MAXN],fac[MAXN];
LL c[MAXN];
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
GetWn();
int n;
while(scanf("%d",&n)!=EOF)
{
n++;
for(int i=;i<n;i++) scanf("%lld",&c[i]);
int m,s=;
scanf("%d",&m);
for(int i=;i<=m;i++)
{
int tmp;
scanf("%d",&tmp);
s=(s+tmp)%MOD;
}
int len=;
while(len<*n) len*=;
mi[]=fac[]=invsum[]=invsum[]=;
for(int i=;i<n;i++)
mi[i]=mi[i-]*(P-s)%MOD;
for(int i=;i<n;i++)
fac[i]=fac[i-]*i%MOD;
for(int i=;i<n;i++)
invsum[i]=inv(fac[i],MOD);
for(int i=;i<n;i++)
A[i]=mi[i]*invsum[i]%MOD;
for(int i=;i<n;i++)
B[i]=c[n-i-]*fac[n-i-]%MOD;
for(int i=n;i<len;i++)
A[i]=B[i]=;
Conv(A, B, len);
for(int i=;i<n;i++)
printf("%lld ",A[n-i-]*invsum[i]%MOD);
printf("\n");
}
return ;
}

HDU 6061 RXD and functions的更多相关文章

  1. 2017 多校3 hdu 6061 RXD and functions

    2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...

  2. HDU 6061 - RXD and functions | 2017 Multi-University Training Contest 3

    每次NTT都忘记初始化,真的是写一个小时,Debug两个小时- - /* HDU 6061 - RXD and functions [ NTT ] | 2017 Multi-University Tr ...

  3. HDU 6061 RXD and functions NTT

    RXD and functions Problem Description RXD has a polynomial function f(x), f(x)=∑ni=0cixiRXD has a tr ...

  4. HDU 6061 RXD and functions(NTT)

    题意 给定一个\(n​\) 次的 \(f​\) 函数,向右移动 \(m​\) 次得到 \(g​\) 函数,第 \(i​\) 次移动长度是 \(a_i​\) ,求 \(g​\) 函数解析式的各项系数,对 ...

  5. HDU 6060 - RXD and dividing | 2017 Multi-University Training Contest 3

    /* HDU 6060 - RXD and dividing [ 分析,图论 ] | 2017 Multi-University Training Contest 3 题意: 给一个 n 个节点的树, ...

  6. HDU 6063 - RXD and math | 2017 Multi-University Training Contest 3

    比赛时候面向过题队伍数目 打表- - 看了题解发现确实是这么回事,分析能力太差.. /* HDU 6063 - RXD and math [ 数学,规律 ] | 2017 Multi-Universi ...

  7. HDU6061 RXD and functions【NTT】

    \(RXD\ and\ functions\) Problem Description RXD has a polynomial function \(f(x)\), \(f(x)=\sum ^{n} ...

  8. HDU 6060 RXD and dividing(思维+计算贡献值)

    http://acm.hdu.edu.cn/showproblem.php?pid=6060 题意: 给定一棵 n 个节点的树,1 为根.现要将节点 2 ~ n 划分为 k 块,使得每一块与根节点形成 ...

  9. 2017 ACM暑期多校联合训练 - Team 3 1008 HDU 6063 RXD and math (莫比乌斯函数)

    题目链接 Problem Description RXD is a good mathematician. One day he wants to calculate: ∑i=1nkμ2(i)×⌊nk ...

随机推荐

  1. 【原创】查询某个SQL在Oracle的会话

    select sql_Text,last_active_time from v$sql where sql_text like '%sql语句%'order by last_active_time

  2. Swift中使用MPMoviePlayerController实现自定义视频播放器界面

    默认情况下播放器自带各种控制按钮,比如前进后退播放暂停等: var url = NSBundle.mainBundle().URLForResource("1", withExte ...

  3. 使用cmstp绕过应用程序白名单

    默认情况下,AppLocker允许在文件夹中执行二进制文件,这是可以绕过它的主要原因.已经发现,这样的二进制文件可以很容易地用于绕过AppLocker和UAC.与Microsoft相关的二进制文件之一 ...

  4. 20165218 《网络对抗技术》 Exp5 MSF基础应用

    Exp5 MSF基础应用 实践内容 主动攻击:ms08_067 exploit/windows/smb/ms08_067_netapi generic/shell_reverse_tcp 针对浏览器攻 ...

  5. D. Dog Show 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    http://codeforces.com/contest/847/problem/D 巧妙的贪心 仔细琢磨... 像凸包里的处理 #include <cstdio> #include & ...

  6. Hadoop基础-HDFS数据清理过程之校验过程代码分析

    Hadoop基础-HDFS数据清理过程之校验过程代码分析 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 想称为一名高级大数据开发工程师,不但需要了解hadoop内部的运行机制,还需 ...

  7. Android的taskAffinity对四种launchMode的影响

    在Android系统中,一个application的所有Activity默认有一个相同的affinity(亲密关系,相似之处).也就是说同一个应用程序的的所有Activity倾向于属于同一个task. ...

  8. bzoj千题计划118:bzoj1028: [JSOI2007]麻将

    http://www.lydsy.com/JudgeOnline/problem.php?id=1028 枚举等待牌 枚举对是哪个 判断 #include<cstdio> #include ...

  9. 脑洞 博弈 E. Competitive Seagulls 2017 ACM Arabella Collegiate Programming Contest

    题目链接:http://codeforces.com/gym/101350/problem/E 题目大意:给你一个长度为n的方格,方格上面都被染色成了白色.每次染色都是选择白色的,假设目前选择的这块白 ...

  10. python核心编程笔记——Chapter8

    Chapter8.条件和循环 这一章感觉有用的点并不多,在我眼里就只有迭代器,列表解析和生成器表达式值得研究而已. 8.2.循环,难度不大. #!usr/bin/env python #-*-codi ...