zoukankan      html  css  js  c++  java
  • 白细胞计数

    总时间限制: 1000ms 内存限制: 65536kB
    题目链接:http://noi.openjudge.cn/ch0109/08/
    描述

    医院采样了某临床病例治疗期间的白细胞数量样本n份,用于分析某种新抗生素对该病例的治疗效果。为了降低分析误差,要先从这n份样本中去除一个数值最大的 样本和一个数值最小的样本,然后将剩余n-2个有效样本的平均值作为分析指标。同时,为了观察该抗生素的疗效是否稳定,还要给出该平均值的误差,即所有有 效样本(即不包括已扣除的两个样本)与该平均值之差的绝对值的最大值。 

    现在请你编写程序,根据提供的n个样本值,计算出该病例的平均白细胞数量和对应的误差。

    输入
    输入的第一行是一个正整数n(2 < n <= 300),表明共有n个样本。
    以下共有n行,每行为一个浮点数,为对应的白细胞数量,其单位为10^9/L。数与数之间以一个空格分开。
    输出
    输出为两个浮点数,中间以一个空格分开。分别为平均白细胞数量和对应的误差,单位也是10^9/L。计算结果需保留到小数点后2位。
    样例输入
    5
    12.0
    13.0
    11.0
    9.0
    10.0
    样例输出
    11.00 1.00
    提示
    为避免浮点精度误差过大,请使用double类型。
     1 #include<stdio.h>
     2 int main()
     3 {
     4     int n,i,maxIndex,minIndex;
     5     double a[305],sum,avg;
     6     double temp,maxDifferenceValue;
     7     scanf("%d",&n);
     8     scanf("%lf",&a[0]);
     9     maxIndex=minIndex=0;
    10     sum=a[0];
    11     for(i=1;i<n;i++)
    12     {
    13         scanf("%lf",&a[i]);
    14         if(a[i]>a[maxIndex]) maxIndex=i;
    15         if(a[i]<a[minIndex]) minIndex=i;
    16         sum=sum+a[i];
    17     }
    18     sum=sum-a[maxIndex]-a[minIndex];
    19     avg=sum/(n-2);
    20 
    21     maxDifferenceValue=-1;
    22     for(i=0;i<n;i++)
    23     {
    24         if(i!=maxIndex&&i!=minIndex)
    25         {
    26             temp=a[i]-avg;
    27             temp=(temp>0?temp:-temp);
    28             if(temp>maxDifferenceValue) maxDifferenceValue=temp;
    29         }
    30     }
    31     printf("%.2lf %.2lf
    ",avg,maxDifferenceValue);
    32     return 0;
    33 }
  • 相关阅读:
    Solaris引导和关闭
    systemctl
    [Poj3281]Dining(最大流)
    [Poj1149]Pigs(最大流)
    [Bzoj2588]Count on a tree(主席树+LCA)
    [BZOJ3524]区间问题(主席树)
    [Poj2761]Feed the dogs(主席树)
    [BZOJ1597][Usaco2008 Mar]土地购买(斜率优化)
    [BSOJ2684]锯木厂选址(斜率优化)
    [Hdu3507]Print Article(斜率优化)
  • 原文地址:https://www.cnblogs.com/huashanqingzhu/p/8393067.html
Copyright © 2011-2022 走看看