3-idiots

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3560    Accepted Submission(s): 1241

Problem Description
  King
OMeGa catched three men who had been streaking in the street. Looking
as idiots though, the three men insisted that it was a kind of
performance art, and begged the king to free them. Out of hatred to the
real idiots, the king wanted to check if they were lying. The three men
were sent to the king's forest, and each of them was asked to pick a
branch one after another. If the three branches they bring back can form
a triangle, their math ability would save them. Otherwise, they would
be sent into jail.
However, the three men were exactly idiots, and
what they would do is only to pick the branches randomly. Certainly,
they couldn't pick the same branch - but the one with the same length as
another is available. Given the lengths of all branches in the forest,
determine the probability that they would be saved.
 
Input
  An integer T(T≤100) will exist in the first line of input, indicating the number of test cases.
Each test case begins with the number of branches N(3≤N≤105).
The following line contains N integers a_i (1≤a_i≤105), which denotes the length of each branch, respectively.
 
Output
  Output the probability that their branches can form a triangle, in accuracy of 7 decimal places.
 
Sample Input
2
4
1 3 3 4
4
2 3 3 4
 
Sample Output
0.5000000
1.0000000
 
  大家都去mod邝斌吧~
 #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int maxn=;
const long double PI=acos(-1.0);
struct complex{
long double r,i;
complex(long double r_=0.0,long double i_=0.0){
r=r_;i=i_;
}
complex operator +(complex &a){
return complex(a.r+r,a.i+i);
}
complex operator -(complex &a){
return complex(r-a.r,i-a.i);
}
complex operator *(complex a){
return complex(r*a.r-i*a.i,i*a.r+a.i*r);
}
}A[maxn]; void Rader(complex *a,int len){
for(int i=,j=len>>;i<len-;i++){
if(i<j)swap(a[i],a[j]);
int k=len>>;
while(j>=k){
j-=k;
k>>=;
}
j+=k;
}
} void FFT(complex *a,int len,int on){
Rader(a,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(1.0,);
for(int k=j;k<j+(h>>);k++){
complex x=a[k];
complex y=a[k+(h>>)]*w;
a[k]=x+y;
a[k+(h>>)]=x-y;
w=w*wn;
}
}
}
if(on==-)
for(int i=;i<len;i++)
a[i].r/=len;
}
int a[maxn];
long long num[maxn];
int main(){
#ifndef ONLINE_JUDGE
//freopen("","r",stdin);
//freopen("","w",stdout);
#endif
int T,n,len=;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
memset(A,,sizeof(A));
memset(num,,sizeof(num));
while(len<=)len<<=;
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a+n+);len=;
while(len<=a[n]*)len<<=;
for(int i=;i<=n;i++)
A[a[i]].r++;
FFT(A,len,);
for(int i=;i<len;i++)
A[i]=A[i]*A[i];
FFT(A,len,-);
for(int i=;i<len;i++)
num[i]=(long long)(A[i].r+0.5);
for(int i=;i<=n;i++)
num[a[i]<<]--;
for(int i=;i<len;i++)
num[i]>>=;
for(int i=;i<len;i++)
num[i]+=num[i-];
long long cnt=;
for(int i=;i<=n;i++){
cnt+=num[len-]-num[a[i]];
cnt-=(long long)(n-i)*(i-);
cnt-=n-;
cnt-=(long long)(n-i)*(n-i-)/;
}
long long tot=((long long)n*(n-)*(n-))/;
printf("%.7lf\n",1.0*cnt/tot);
}
return ;
}

FFT(快速傅里叶变换):HDU 4609 3-idiots的更多相关文章

  1. FFT 快速傅里叶变换 学习笔记

    FFT 快速傅里叶变换 前言 lmc,ikka,attack等众多大佬都没教会的我终于要自己填坑了. 又是机房里最后一个学fft的人 早背过圆周率50位填坑了 用处 多项式乘法 卷积 \(g(x)=a ...

  2. CQOI2018 九连环 打表找规律 fft快速傅里叶变换

    题面: CQOI2018九连环 分析: 个人认为这道题没有什么价值,纯粹是为了考算法而考算法. 对于小数据我们可以直接爆搜打表,打表出来我们可以观察规律. f[1~10]: 1 2 5 10 21 4 ...

  3. 「学习笔记」FFT 快速傅里叶变换

    目录 「学习笔记」FFT 快速傅里叶变换 啥是 FFT 呀?它可以干什么? 必备芝士 点值表示 复数 傅立叶正变换 傅里叶逆变换 FFT 的代码实现 还会有的 NTT 和三模数 NTT... 「学习笔 ...

  4. FFT —— 快速傅里叶变换

    问题: 已知A[], B[], 求C[],使: 定义C是A,B的卷积,例如多项式乘法等. 朴素做法是按照定义枚举i和j,但这样时间复杂度是O(n2). 能不能使时间复杂度降下来呢? 点值表示法: 我们 ...

  5. 浅谈FFT(快速傅里叶变换)

    本文主要简单写写自己在算法竞赛中学习FFT的经历以及一些自己的理解和想法. FFT的介绍以及入门就不赘述了,网上有许多相关的资料,入门的话推荐这篇博客:FFT(最详细最通俗的入门手册),里面介绍得很详 ...

  6. [C++] 频谱图中 FFT快速傅里叶变换C++实现

    在项目中,需要画波形频谱图,因此进行查找,不是很懂相关知识,下列代码主要是针对这篇文章. http://blog.csdn.net/xcgspring/article/details/4749075 ...

  7. matlab中fft快速傅里叶变换

    视频来源:https://www.bilibili.com/video/av51932171?t=628. 博文来源:https://ww2.mathworks.cn/help/matlab/ref/ ...

  8. FFT快速傅里叶变换算法

    1.FFT算法概要: FFT(Fast Fourier Transformation)是离散傅氏变换(DFT)的快速算法.即为快速傅氏变换.它是根据离散傅氏变换的奇.偶.虚.实等特性,对离散傅立叶变换 ...

  9. FFT快速傅里叶变换

    FFT太玄幻了,不过我要先膜拜HQM,实在太强了 1.多项式 1)多项式的定义 在数学中,由若干个单项式相加组成的代数式叫做多项式.多项式中的每个单项式叫做多项式的项,这些单项式中的最高项次数,就是这 ...

  10. [学习笔记]FFT——快速傅里叶变换

    大力推荐博客: 傅里叶变换(FFT)学习笔记 一.多项式乘法: 我们要明白的是: FFT利用分治,处理多项式乘法,达到O(nlogn)的复杂度.(虽然常数大) FFT=DFT+IDFT DFT: 本质 ...

随机推荐

  1. Adding Validation to our Album Forms 添加类属性的一些验证特性

    Adding Validation to our Album Forms We’ll use the following Data Annotation attributes: Required – ...

  2. 多列的行列转换(PIVOT,UNPIVOT)

    形式1 形式2 形式3 有时候可能会有这样的需求: 将一张表的所有列名转做为数据的一列数据,将一列数据作为整张表的列名 当列比较多时,只用PIVOT是解决不了的,经过研究,需要将UNPIVOT 和 P ...

  3. 【转】iOS开发UI篇—程序启动原理和UIApplication

    原文 http://www.cnblogs.com/wendingding/p/3766347.html   一.UIApplication 1.简单介绍 (1)UIApplication对象是应用程 ...

  4. 【转】 iOS开发UI篇—UIScrollView控件实现图片轮播

    原文:http://www.cnblogs.com/wendingding/p/3763527.html iOS开发UI篇—UIScrollView控件实现图片轮播 一.实现效果 实现图片的自动轮播 ...

  5. RESTful互联网框架

    在我们日常接触的网络中,对于非程序员来说主要关注的就是在网上找到自己需要的资料,但是对于开发者来说,主要关注的就是将结构和页面,以及功能的分离,但是如何划分这个结构呢,或许我们知道的有MVC框架,甚至 ...

  6. 最新xgboost python32位下安装xgboost

    网上很多windows python下安装xgboost都是很简单的几步无非是visual studio2013以上版本编译,安装.但现在最新的xgboost已经移除了c++工程文件,找到旧版本的也多 ...

  7. 调用数据库过程函数mysql

    Connection conn=JdbcUtil.getConnection();//JdbcUtil是我写的获取connection的工具类 CallableStatement cast=conn. ...

  8. 『重构--改善既有代码的设计』读书笔记----Hide Delegate

    所谓委托关系,就是一个类对于另一个类来说纯粹作为接口转发,即客户通过一个委托类去调用另一个对象.直白的委托关系就是委托类直接返回出目标类给客户调用,这个关系很麻烦,因为委托关系的变动就会影响客户端的代 ...

  9. 基于jQuery选择器的整理集合

    jquery对象访问1.each(callback):以每个匹配的元素作为上下文来执行一个函数,return false;停止循环;return true;跳至下一个循环. 来个实例 : 代码如下: ...

  10. 【转载】详细解读C#中的 .NET 弱事件模式

    你可能知道,事件处理是内存泄漏的一个常见来源,它由不再使用的对象存留产生,你也许认为它们应该已经被回收了,但不是,并有充分的理由. 在这个短文中(期望如此),我会在 .Net 框架的上下文事件处理中展 ...