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 多项式的更多相关文章

  1. 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 ...

  2. bzoj 3513: [MUTC2013]idiots FFT

    bzoj 3513: [MUTC2013]idiots FFT 链接 bzoj 思路 参考了学姐TRTTG的题解 统计合法方案,最后除以总方案. 合法方案要不好统计,统计不合法方案. \(a+b< ...

  3. hdu 4709:Herding(叉积求三角形面积+枚举)

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  4. 学习数论 HDU 4709

    经过杭师大校赛的打击,明白了数学知识的重要性 开始学习数论,开始找题练手 Herding HDU - 4709 Little John is herding his father's cattles. ...

  5. hdu 5730 Shell Necklace [分治fft | 多项式求逆]

    hdu 5730 Shell Necklace 题意:求递推式\(f_n = \sum_{i=1}^n a_i f_{n-i}\),模313 多么优秀的模板题 可以用分治fft,也可以多项式求逆 分治 ...

  6. HDU 1402 A * B Problem Plus 快速傅里叶变换 FFT 多项式

    http://acm.hdu.edu.cn/showproblem.php?pid=1402 快速傅里叶变换优化的高精度乘法. https://blog.csdn.net/ggn_2015/artic ...

  7. hdu 5142 NPY and FFT

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5142 NPY and FFT Description A boy named NPY is learn ...

  8. HDU 4609 3-idiots(FFT)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4609 题意:给出n个正整数(数组A).每次随机选出三个数.问这三个数能组成三角形的概率为多大? 思路: ...

  9. hdu - 4709 - Herding

    题意:给出N个点的坐标,从中取些点来组成一个多边形,求这个多边形的最小面积,组不成多边形的输出"Impossible"(测试组数 T <= 25, 1 <= N < ...

随机推荐

  1. IIS发布MVC出错

    一个MVC网站在发布到IIS上时,出现了这个问题: 然后解决办法: 然后应用程序池那里,自己点右键添加一个 新建完应用池之后选中点高级设置 最后,添加网站,添加网站的时候应用程序池选择自己刚刚新建的那 ...

  2. bzoj千题计划233:bzoj 1304: [CQOI2009]叶子的染色

    http://www.lydsy.com/JudgeOnline/problem.php?id=1304 结论1:根节点一定染色 如果根节点没有染色,选择其子节点的一个颜色,那么所有这个颜色的子节点都 ...

  3. scrapy 简单防封

    设置爬取间隔 setting.py from random import random DOWNLOAD_DELAY = random()* ps:此次的爬取间隔,在读取seeting文件确定,并非每 ...

  4. [转载]Understanding the Bootstrap 3 Grid System

    https://scotch.io/tutorials/understanding-the-bootstrap-3-grid-system With the 3rd version of the gr ...

  5. Linux - ssh 连接慢解决

    解决 ssh 链接慢 sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config sed -i ...

  6. linux下brctl配置网桥

    原文:http://zhumeng8337797.blog.163.com/blog/static/1007689142011643834429/ 先装好网卡,连上网线,这是废话,不用说了. 然后开始 ...

  7. xtrabackup 恢复单个表【转】

    一.安装与备份 1. 下载安装XtraBackup$wget http://www.percona.com/redir/downloads/XtraBackup/LATEST/binary/tarba ...

  8. 高可用的MongoDB集群【转】

    刚接触MongoDB,就要用到它的集群,只能硬着头皮短时间去看文档和尝试自行搭建.迁移历史数据更是让人恼火,近100G的数据文件,导入.清理垃圾数据执行的速度蜗牛一样的慢.趁着这个时间,把这几天关于M ...

  9. 修改MySQL的时区,涉及参数time_zone

    原地址:http://blog.csdn.net/mchdba/article/details/9763521 首先需要查看mysql的当前时区,用time_zone参数 mysql> show ...

  10. android 调用系统照相机拍照后保存到系统相册,在系统图库中能看到

    需求:  调用系统照相机进行拍照,并且保存到系统相册,调用系统相册的时候能看到   系统相册的路径:String cameraPath= Environment.getExternalStorageD ...