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邝斌吧~
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cstdio>
  5. #include <cmath>
  6. using namespace std;
  7. const int maxn=;
  8. const long double PI=acos(-1.0);
  9. struct complex{
  10. long double r,i;
  11. complex(long double r_=0.0,long double i_=0.0){
  12. r=r_;i=i_;
  13. }
  14. complex operator +(complex &a){
  15. return complex(a.r+r,a.i+i);
  16. }
  17. complex operator -(complex &a){
  18. return complex(r-a.r,i-a.i);
  19. }
  20. complex operator *(complex a){
  21. return complex(r*a.r-i*a.i,i*a.r+a.i*r);
  22. }
  23. }A[maxn];
  24.  
  25. void Rader(complex *a,int len){
  26. for(int i=,j=len>>;i<len-;i++){
  27. if(i<j)swap(a[i],a[j]);
  28. int k=len>>;
  29. while(j>=k){
  30. j-=k;
  31. k>>=;
  32. }
  33. j+=k;
  34. }
  35. }
  36.  
  37. void FFT(complex *a,int len,int on){
  38. Rader(a,len);
  39. for(int h=;h<=len;h<<=){
  40. complex wn(cos(-on*PI*/h),sin(-on*PI*/h));
  41. for(int j=;j<len;j+=h){
  42. complex w(1.0,);
  43. for(int k=j;k<j+(h>>);k++){
  44. complex x=a[k];
  45. complex y=a[k+(h>>)]*w;
  46. a[k]=x+y;
  47. a[k+(h>>)]=x-y;
  48. w=w*wn;
  49. }
  50. }
  51. }
  52. if(on==-)
  53. for(int i=;i<len;i++)
  54. a[i].r/=len;
  55. }
  56. int a[maxn];
  57. long long num[maxn];
  58. int main(){
  59. #ifndef ONLINE_JUDGE
  60. //freopen("","r",stdin);
  61. //freopen("","w",stdout);
  62. #endif
  63. int T,n,len=;
  64. scanf("%d",&T);
  65. while(T--){
  66. scanf("%d",&n);
  67. memset(A,,sizeof(A));
  68. memset(num,,sizeof(num));
  69. while(len<=)len<<=;
  70. for(int i=;i<=n;i++)
  71. scanf("%d",&a[i]);
  72. sort(a+,a+n+);len=;
  73. while(len<=a[n]*)len<<=;
  74. for(int i=;i<=n;i++)
  75. A[a[i]].r++;
  76. FFT(A,len,);
  77. for(int i=;i<len;i++)
  78. A[i]=A[i]*A[i];
  79. FFT(A,len,-);
  80. for(int i=;i<len;i++)
  81. num[i]=(long long)(A[i].r+0.5);
  82. for(int i=;i<=n;i++)
  83. num[a[i]<<]--;
  84. for(int i=;i<len;i++)
  85. num[i]>>=;
  86. for(int i=;i<len;i++)
  87. num[i]+=num[i-];
  88. long long cnt=;
  89. for(int i=;i<=n;i++){
  90. cnt+=num[len-]-num[a[i]];
  91. cnt-=(long long)(n-i)*(i-);
  92. cnt-=n-;
  93. cnt-=(long long)(n-i)*(n-i-)/;
  94. }
  95. long long tot=((long long)n*(n-)*(n-))/;
  96. printf("%.7lf\n",1.0*cnt/tot);
  97. }
  98. return ;
  99. }

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. webfont自定义字体的实现方案

    对于做Web前端的人来说,现在不知道webfont为何物似乎显得有点low了.webfont固然可爱,但似乎仍只可远观,不可亵玩.原因就在于中文字体库体积庞大,远比26个字母来的复杂.于是有同学就说了 ...

  2. 监听指定端口数据交互(HttpListenerContext )

    很怀念以前做机票的日子,,,,可惜回不去 以前的项目中的,拿来贴贴 场景:同步第三方数据,监听指定地址(指定时间间隔,否则不满足,因为需要处理粘包问题,改篇未实现) 主要内容四个文件:下面分别说下每个 ...

  3. 关于“SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问 ”

    原因:在从远程服务器复制数据到本地时出现“SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatas ...

  4. 数据库连接报错之IO异常(The Network Adapter could not establish the connection)

    Io 异常: The Network Adapter could not establish the connection 有以下四个原因: 1.oracle配置 listener.ora 和tnsn ...

  5. What and where are the stack and heap?

    The stack is the memory set aside as scratch space for a thread of execution. When a function is cal ...

  6. Visual Studio2010 安装msdn

    1.注册VS2010 断网(不要冒险)->运行Microsoft Visual Studio 2010->帮助->注册产品->YCFHQ-9DWCY-DKV88-T2TMH-G ...

  7. 关于 ASP.NET 验证码

    Session["CheckCode"] 这个..不懂神马意思.. .创建一个用户控件 用户名:TextBox 密码: TextBox 验证码:TextBox 验证码图片 < ...

  8. webpack学习笔记一(入门)

    webpack集成了模块加载和打包等功能 ,这两年在前端领域越来越受欢迎.平时一般是用requirejs.seajs作为模块加载用,用grunt/gulp作为前端构建.webpack作为模块化加载兼容 ...

  9. modifytime是一个神奇的column name----这边文章是错的totally,因为我的实验不彻底。timestamp属性很神奇,头一个timestamp,会自动的成DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

    在mysql里边modifytime是一个神奇的column name,试一下. 请执行sql语句 CREATE TABLE `test_time` ( `modifytime` timestamp ...

  10. ajax 文件上传,ajax

    ajax 文件上传,ajax 啥也不说了,直接上代码! <input type="file" id="file" name="myfile&qu ...