当前位置:编程学习 > C/C++ >>

HDOJ - 4503 湫湫系列故事——植树节

Program:


[cpp]
#include<iostream>  
#include<stdio.h>  
#include<string.h>  
#include<cmath>  
#include<algorithm>  
#define ll long long  
using namespace std;   
int n; 
int main() 
{    
    //  freopen("input.txt","r",stdin);   freopen("output.txt","w",stdout);   
      int T,x,i,sum,m; 
      scanf("%d",&T); 
      while (T--) 
      { 
            scanf("%d",&n); 
            sum=n*(n-1)*(n-2)/6; 
            m=0; 
            for (i=1;i<=n;i++) 
            { 
                 scanf("%d",&x); 
                 m+=x*(n-1-x); 
            } 
            m/=2; 
            m=sum-m; 
            printf("%.3lf\n",m*1.0/sum); 
      } 
      return 0; 

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,