bzoj 4827: [Hnoi2017]礼物 [fft]
4827: [Hnoi2017]礼物
题意:略
以前做的了
化一化式子就是一个卷积和一些常数项
我记着确定调整值还要求一下导...
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = (1<<18)+5, INF=1e9+5;
const double PI = acos(-1.0);
inline int read() {
char c=getchar(); int x=0,f=1;
while(c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();}
while(c>='0' && c<='9') {x=x*10+c-'0'; c=getchar();}
return x*f;
}
struct meow {
double x, y;
meow(double a=0, double b=0) : x(a), y(b) {}
};
meow operator + (meow a, meow b) {return meow(a.x + b.x, a.y + b.y);}
meow operator - (meow a, meow b) {return meow(a.x - b.x, a.y - b.y);}
meow operator * (meow a, meow b) {return meow(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);}
meow conj(meow a) {return meow(a.x, -a.y);}
typedef meow cd;
namespace fft {
int n, rev[N];
cd omega[N], omegaInv[N];
void init(int lim) {
n=1; int k=0; while(n<lim) n<<=1, k++;
for(int i=0; i<n; i++) rev[i] = (rev[i>>1]>>1) | ((i&1)<<(k-1));
for(int i=0; i<n; i++) {
omega[i] = cd(cos(2*PI/n*i), sin(2*PI/n*i));
omegaInv[i] = conj(omega[i]);
}
}
void dft(cd *a, int flag) {
cd *w = flag > 0 ? omega : omegaInv;
for(int i=0; i<n; i++) if(i < rev[i]) swap(a[i], a[rev[i]]);
for(int l=2; l<=n; l<<=1) {
int m = l>>1;
for(cd *p=a; p!=a+n; p+=l)
for(int k=0; k<m; k++) {
cd t = w[n/l*k] * p[k+m];
p[k+m] = p[k] - t;
p[k] = p[k] + t;
}
}
if(flag == -1) for(int i=0; i<n; i++) a[i].x /= n;
}
void mul(cd *a, cd *b) {
dft(a, 1); dft(b, 1);
for(int i=0; i<n; i++) a[i] = a[i] * b[i];
dft(a, -1);
}
}
int n, m, x[N], y[N]; ll ans, sum, t;
cd a[N], b[N];
int main() {
freopen("in", "r", stdin);
n=read(); m=read();
for(int i=1; i<=n; i++) a[i].x = x[i] = read(), ans += x[i] * x[i];
for(int i=1; i<=n; i++) b[n-i+1].x = b[n-i+1+n].x = y[i] = read(), ans += y[i] * y[i], sum += x[i] - y[i];
sum = abs(sum);
ll c = floor((double) sum / n + 0.5); //printf("c %lld\n", c);
ans += c * (n * c - 2 * sum);
//printf("ans %lld\n", ans);
fft::init(n+n+1);
fft::mul(a, b);
for(int i=n+1; i<=n+n; i++) t = max(t, (ll)floor(a[i].x + 0.5));// printf("a %d %lf\n", i, a[i].x);
t *= 2;
//printf("t %lld\n", t);
printf("%lld", ans - t);
}
bzoj 4827: [Hnoi2017]礼物 [fft]的更多相关文章
- bzoj 4827 [Hnoi2017]礼物——FFT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4827 式子就是 \sum_{i=0}^{n-1}(a[ i ] - b[ i+k ] + c ...
- bzoj 4827 [Hnoi2017] 礼物 —— FFT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4827 首先,旋转对应,可以把 b 序列扩展成2倍,则 a 序列对应到的还是一段区间: 再把 ...
- BZOJ 4827 [Hnoi2017]礼物 ——FFT
题目上要求一个循环卷积的最小值,直接破环成链然后FFT就可以了. 然后考虑计算的式子,可以分成两个部分分开计算. 前半部分FFT,后半部分扫一遍. #include <map> #incl ...
- bzoj 4827: [HNOI2017]礼物 (FFT)
一道FFT 然而据说暴力可以水70分 然而我省选的时候看到了直接吓傻了 连暴力都没打 太弱了啊QAQ emmmm 详细的拆开就看其他题解吧233 最后那一步卷积其实我一直没明白 后来画画图终于懂了 ...
- bzoj 4827: [Hnoi2017]礼物【FFT】
记得FFT要开大数组!!开到快MLE的那种!!我这个就是例子TAT,5e5都RE了 在这题上花的时间太多了,还是FFT不太熟练. 首先看70分的n方做法:从0下标开始存,先n--,把a数组倍增,然后枚 ...
- 【刷题】BZOJ 4827 [Hnoi2017]礼物
Description 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一个送给她.每个手环上各有 n 个装饰物,并且每个装饰物都有一定的亮度.但是在 ...
- BZOJ 4827: [Hnoi2017]礼物 FFT_多项式_卷积
题解稍后在笔记本中更新 Code: #include <bits/stdc++.h> #define setIO(s) freopen(s".in","r&q ...
- BZOJ:4827: [Hnoi2017]礼物
[问题描述] 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一个送给她.每个手环上各有 n 个装饰物,并且每个装饰物都有一定的亮度. 但是在她生日的 ...
- 4827: [Hnoi2017]礼物
4827: [Hnoi2017]礼物 链接 分析: 求最小的$\sum_{i=1}^{n}(x_i-y_i)^2$ 设旋转了j位,每一位加上了c. $\sum\limits_{i=1}^{n}(x_{ ...
随机推荐
- 数塔~~dp学习_1
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 数塔 Time Limit: 1000/1000 MS (Java/Others) Mem ...
- HDU 2243 Knight Moves
题目: A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find th ...
- Responder Pro new version could analyze Win10 memory dump
My friend John acquired a memory dump from Windows 10, but he could analyze this memory dump with an ...
- 如何在Chrome下使用Postman进行rest请求测试
在web和移动端开发时,常常会调用服务器端的restful接口进行数据请求,为了调试,一般会先用工具进行测试,通过测试后才开始在开发中使用.这里介绍一下如何在chrome浏览器利用postman应用进 ...
- PHP编码规范及建议
<h3 align="center">PHP编码规范及建议</h3>### 编码规范- PHP代码文件必须以 <?php 标签开始.```<?p ...
- 电脑如何防蹭网?使用防蹭网功能杜绝未知设备连接WiFi
发布时间:2015-09-27 15:24发布者:系统城-shaojing浏览数:733 网络越来越卡?网页打开越来越慢?如果你有以上疑问,那么就要确认自己是不是被"蹭网"了.尽管 ...
- 每天一个linux命令(34):du 命令
Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的. 1.命令格式: du [选项][文件] 2.命令功能 ...
- dedecms系统后台登陆提示用户名密码不存在
dedecms最近被曝有非常多的安全漏洞,最近有些用户反应后台管理员账号密码没有修改但无法正常登陆,提示用户名不存在,经研究发现是程序漏洞管理员被直接篡改,解决方案如下. 工具/原料 dedecms ...
- 对[UIApplication sharedApplication]理解
[ sharedApplication]返回UIApplication * application = nil; +(UIApplication*) shareApplication{ if(appl ...
- 关于userInteractionEnabled的属性的理解
userInteractionEnabled A Boolean value that determines whether user events are ignored and removed f ...