HDU 4709 3-idiots FFT 多项式
http://acm.hdu.edu.cn/showproblem.php?pid=4609
给一堆边,求这一堆边随便挑三个能组成三角形的概率。
裸fft,被垃圾题解坑了还以为很难。
最长的边的长度小于其余两边之和是组成三角形的充要条件,fft搞搞就行了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<complex>
using namespace std;
#define LL long long
const int maxn=;
double Pi;
typedef complex< double >cd;
cd b[maxn]={};
LL a[maxn]={},cnt[maxn]={};
int bel[maxn]={},s,bt;
void getit(){for(int i=;i<s;++i)bel[i]=(bel[i>>]>>)|((i&)<<(bt-));}
void fft(cd *c,int n,int dft){
for(int i=;i<n;++i)if(bel[i]>i)swap(c[i],c[bel[i]]);
for(int step=;step<n;step<<=){
cd w=cd(cos(Pi/(double)step),sin(Pi/(double)step)*(double)dft);
for(int j=;j<n;j+=(step<<)){
cd z=cd(1.0,);
for(int i=j;i<j+step;++i){
cd x=c[i],y=c[i+step]*z;
c[i]=x+y;c[i+step]=x-y;
z=z*w;
}
}
}
if(dft==-)for(int i=;i<n;++i)c[i]/=n;
}
int main(){
Pi=acos(-1.0);
int T;scanf("%d",&T);
while(T-->){
int n;scanf("%d",&n);
memset(cnt,,sizeof(cnt));
for(int i=;i<n;++i){scanf("%d",&a[i]);cnt[a[i]]+=;} sort(a,a+n); int siz=a[n-]+;
for(int i=;i<siz;++i)b[i]=cd(cnt[i],);
for(int i=siz;i<s;++i)b[i]=cd(,); siz*=; bt=; s=; for(;s<siz;++bt)s<<=; getit();
fft(b,s,);
for(int i=;i<s;++i)b[i]=b[i]*b[i];
fft(b,s,-);
for(int i=;i<=s;++i)cnt[i]=(LL)(b[i].real()+0.5);
for(int i=;i<s;++i)b[i]=cd(,); s=a[n-]*;
for(int i=;i<n;++i)--cnt[a[i]*];
for(int i=;i<=s;++i)cnt[i]/=;
for(int i=;i<=s;++i)cnt[i]+=cnt[i-]; LL ans=;
for(int i=;i<n;++i){
ans+=cnt[s]-cnt[a[i]];
ans-=(LL)(n--i)*i;
ans-=n-;
ans-=(LL)(n--i)*(n-i-)/;
}
LL sum=(LL)n*(n-)*(n-)/;
printf("%.7f\n",(double)(ans)/(double)(sum));
}
return ;
}
HDU 4709 3-idiots FFT 多项式的更多相关文章
- 51NOD 1258 序列求和 V4 [任意模数fft 多项式求逆元 伯努利数]
1258 序列求和 V4 题意:求\(S_m(n) = \sum_{i=1}^n i^m \mod 10^9+7\),多组数据,\(T \le 500, n \le 10^{18}, k \le 50 ...
- bzoj 3513: [MUTC2013]idiots FFT
bzoj 3513: [MUTC2013]idiots FFT 链接 bzoj 思路 参考了学姐TRTTG的题解 统计合法方案,最后除以总方案. 合法方案要不好统计,统计不合法方案. \(a+b< ...
- hdu 4709:Herding(叉积求三角形面积+枚举)
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- 学习数论 HDU 4709
经过杭师大校赛的打击,明白了数学知识的重要性 开始学习数论,开始找题练手 Herding HDU - 4709 Little John is herding his father's cattles. ...
- hdu 5730 Shell Necklace [分治fft | 多项式求逆]
hdu 5730 Shell Necklace 题意:求递推式\(f_n = \sum_{i=1}^n a_i f_{n-i}\),模313 多么优秀的模板题 可以用分治fft,也可以多项式求逆 分治 ...
- HDU 1402 A * B Problem Plus 快速傅里叶变换 FFT 多项式
http://acm.hdu.edu.cn/showproblem.php?pid=1402 快速傅里叶变换优化的高精度乘法. https://blog.csdn.net/ggn_2015/artic ...
- hdu 5142 NPY and FFT
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5142 NPY and FFT Description A boy named NPY is learn ...
- HDU 4609 3-idiots(FFT)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4609 题意:给出n个正整数(数组A).每次随机选出三个数.问这三个数能组成三角形的概率为多大? 思路: ...
- hdu - 4709 - Herding
题意:给出N个点的坐标,从中取些点来组成一个多边形,求这个多边形的最小面积,组不成多边形的输出"Impossible"(测试组数 T <= 25, 1 <= N < ...
随机推荐
- 2-SAT问题的方案输出
2-sat 推荐学习资料: 伍昱的2003年IOI国家集训队论文<由对称性解2-sat问题> 论文链接:https://wenku.baidu.com/view/31fd7200bed5b ...
- Codeforces 543 B. World Tour
http://codeforces.com/problemset/problem/543/B 题意: 给定一张边权均为1的无向图. 问至多可以删除多少边,使得s1到t1的最短路不超过l1,s2到t2的 ...
- 均方根值(RMS)+ 均方根误差(RMSE)+标准差(Standard Deviation)
均方根值(RMS)+ 均方根误差(RMSE)+标准差(Standard Deviation) 1.均方根值(RMS)也称作为效值,它的计算方法是先平方.再平均.然后开方. 2.均方根误差,它是观测值 ...
- 滚动视差插件skrollr.js
东西虽好,但也不能懒到自己一点都不去做总结,那么下方将会写出从网上找到,比较好的网址(应该是根据官网翻译的). 自己先做一个总结:这个插件兼容上做到了降级处理,虽然低端浏览器没有那么顺畅的效果,但是勉 ...
- Linux 并发链接数
并发数查看 查看 TCP 协议连接数 netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' SYN_RECV # ...
- 第9月第15天 设计模式 adapter mvc
1. 有一道iOS面试题,iOS中都有什么设计模式?很少有答案说包括adapter. gof 书中adapter模式有以下内容: 实现: ... b ) 使 用 代 理 对 象 在这种方法中, T r ...
- Windows::Docker::Ubuntu 做 SLAM
如题,这是一件很蛋疼的事情. 为了完成这一件事情,需要达成目标: Ubuntu GUI 必须要能够显示. Ubuntu 可以链接 USB Camera. 目标一 目标1很容易达成. 在 Win10 中 ...
- Spring容器是如何实现 Bean 自动注入(xml)
入口web.xml web.xml 配置文件 <!-- Spring Config --> <listener> <listener-class>org.sprin ...
- mysqlbinlog 查看mysql bin 日志 mysqlbinlog: unknown variable 'default-character-set=utf8'
mysqlbinlog mysql-bin.000036 | less 查询包含几个字段的语句: mysqlbinlog mysql-bin.000036| egrep '(201103061000 ...
- mac 安装gevent报错
运行pip install gevent报错 错误信息如下 xcrun: error: invalid active developer path (/Library/Developer/Comman ...