Grey Area(数学统计题)

Grey Area

Time Limit: 2000ms

Memory Limit: 65536KB

64-bit integer IO format: %lld      Java class name:
Main

Special Judge

Submit
Status PID: 1083

Dr. Grey is a data analyst, who visualizes various aspects of data received from all over the world everyday. He is extremely good at sophisticated visualization tools, but yet his favorite is a simple self-made histogram generator.

Figure 1 is an example of histogram automatically produced by his histogram generator. A histogram is a visual display of frequencies of value occurrences as bars. In this example, values in the interval 0-9 occur five times, those in the interval 10-19 occur
three times, and 20-29 and 30-39 once each.

Dr. Grey‘s histogram generator is a simple tool. First, the height of the histogram is fixed, that is, the height of the highest bar is always the same and those of the others are automatically adjusted proportionately. Second, the widths of bars are also fixed.
It can only produce a histogram of uniform intervals, that is, each interval of a histogram should have the same width (10 in the above example). Finally, the bar for each interval is painted in a grey color, where the colors of the leftmost and the rightmost
intervals are black and white, respectively, and the darkness of bars monotonically decreases at the same rate from left to right. For instance, in Figure 1, the darkness levels of the four bars are 1, 2/3, 1/3 and 0, respectively.

In this problem, you are requested to estimate ink consumption when printing a histogram on paper. The amount of ink necessary to draw a bar is proportional to both its area and darkness.

Input

The input consists of multiple datasets, each of which contains integers and specifies a value table and intervals for the histogram generator, in the following format.

n w

v1

v2

.

.

.

vn

n is the total number of value occurrences for the histogram, and each of the n lines following the first line contains a single value. Note that the same value may possibly occur multiple times.

w is the interval width. A value v is in the first (i.e. leftmost) interval if 0 ≤ v < w, the second one if w ≤ v < 2w, and so on. Note that the interval from 0 (inclusive) to w (exclusive) should be regarded as the leftmost even if no values occur in this
interval. The last (i.e. rightmost) interval is the one that includes the largest value in the dataset.

You may assume the following.

1 ≤ n ≤ 100

10 ≤ w ≤ 50

0 ≤ vi ≤ 100 for 1 ≤ i ≤ n

You can also assume that the maximum value is no less than w. This means that the histogram has more than one interval.

The end of the input is indicated by a line containing two zeros.

Output

For each dataset, output a line containing the amount of ink consumed in printing the histogram.

One unit of ink is necessary to paint one highest bar black. Assume that 0:01 units of ink per histogram is consumed for various purposes except for painting bars such as drawing lines and characters (see Figure 1). For instance, the amount of ink consumed
in printing the histogram in Figure 1 is:

1 × 1 + 2/3 × 3/5 + 1/3 × 1/5 + 0 × 1/5 + 0.01

= 1 + 2/5 + 1/15 + 0.01

= 1.47666...

Each output value should be in a decimal fraction and may have an error less than 10-5.

Sample Input

3 50
100
0
100
3 50
100
100
50
10 10
1
2
3
4
5
16
17
18
29
30
0 0

Sample Output

0.51
0.26
1.4766666666666667

Hint

Special judge problem, you may get "Wrong Answer" when output in wrong format.

题意 :关键在读懂题意
要你计算画一张直方图所需要用的墨量 直线所用墨量固定为0.01  n个数据  每个数据固定宽度 w

墨水是渐变的 为总得高度逐步减0(变白了) 

样例 100 0 100

100的频高 100/50 

100 的频数 2

0 的平高为 0

频数为 1

ans=1/2*(2/2)+ 0/2*(1/2) + 2/2*(0/2)+ 0.01

0.51

100 100 50

ans = 0*(2/2) + 1/2*(1/2) +  2/2*(0/2)+0.01

(比赛的时候 英文不好的我把v看成了频高 坑了队友 1h 最后他无奈用百度翻译了一下 发现了问题)

#include<bits/stdc++.h>
using namespace std;

int res[100];
int main()
{
    //freopen("a.txt","r",stdin);
    int n,m;
    while(scanf("%d%d",&n,&m),n+m)
    {
        memset(res,0,sizeof(res));
        int mx=0;
        while(n--)
        {
            int a;
            scanf("%d",&a);
            int t=a/m;
            if(t>mx)
                mx=t;
            res[t]++;
        }
        int num=0;
        for(int i=0; i<=mx; i++)
        {
            if(res[i]==0)
                continue;
            if(res[i]>num)
                num=res[i];
        }
        double ans=0.0;
        int h=mx+1;
        for(int i=0; i<mx; i++)
        {
            h--;
            //printf("%d  %d  %d\n",h,i,res[i]);
            if(res[i]==0)
                continue;
            ans+=res[i]*1.0/num*(h*1.0/mx);//(h*1.0/mx)为墨量比例的渐变量
        }
        ans+=0.01;
        printf("%.7lf\n",ans);
    }
    return 0;
}
时间: 2024-11-08 09:16:36

Grey Area(数学统计题)的相关文章

2018高考数学真题权威专家评析+2019备考方向解读

2018高考数学真题汇总!权威专家评析+2019备考方向解读 "试卷稳中求新,在保持结构总体稳定基础上,科学灵活地确定试题内容,强调数学应用,突出关键能力."教育部考试中心命题专家认为,2018年高考数学卷一个突出的特点是,根据文理科考生数学素养综合要求,调整文理科同题比例,为新一轮高考数学不分文理科的改革进行了积极探索. 探索内容改革,助推素质教育 教育部考试中心命题专家介绍,根据文理科考生数学素养的综合要求,调整全国Ⅱ卷.全国Ⅲ卷文理科同题比例,为新一轮高考数学不分文理科改革进行了

数学趣味题(相邻同加同减问题)

想要弥补数学方面的知识于是我看了刘汝佳老师的算法艺术. 从简单开始在这里记录一下. 题目的描述 很容易理解但是让我想的话,我会感觉很困难. 似乎见到多了,对这种问题有一种天生的恐惧. 但是学习嘛,一点一点积累. 刘汝佳老师这样讲到. 先把8个点归为红色和蓝色两类. 相邻的点不在同一类中. 假设我们先看一下最下面的ABCD四个点,假设A点有a个麻烦子,B点有b个麻烦子,C点有c个,D点有d个. 我们先让A,B同时增加c个,然后让B,C同时减少c个,这样就C就没有了,而A中多了c个.这样我们就能把同

hdu 3641 数论 二分求符合条件的最小值数学杂题

http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*==================================================== 二分查找符合条件的最小值 ======================================================*/ ll solve() { __int64 low = 0, high = INF, mid ; while(low <=

Acdreamoj1115(数学思维题)

题意:1,3是完美数,如果a,b是完美数,则2+a*b+2*a+2*b,判断给出的n是否是完美数. 解法:开始只看出来2+a*b+2*a+2*b=(a+2)*(b+2)-2,没推出更多结论,囧.没办法,只能暴力将所有的完美数求出来然后查表.正解是c+2=(a+2)*(b+2);完美数都是有质因子3或5组成的(5本身除外): 自己暴力代码: /****************************************************** * author:xiefubao *****

hdu 4961 数学杂题

http://acm.hdu.edu.cn/showproblem.php?pid=4961 先贴个O(nsqrtn)求1-n所有数的所有约数的代码: vector<int>divs[MAXN]; void caldivs() { for(int i=1;i<MAXN;i++) for(int j=i;j<MAXN;j+=i) divs[j].push_back(i); } 有了这个当时理下思路就可写了,但是重复数处理注意: 1.用一个数组vis[]  vis[i]=1表示i存在

【算法学习笔记】73.数学规律题 SJTU OJ 1058 小M的机器人

Description 小M有很多个机器人,他们要么一直说真话,要么一直说假话. 然后每个人都说: (1). 不到N个人比我工作得多 (2). 至少M个人的工资比我高. 保证没有两个人的工作一样重,也没有两个人的工资一样高,问至少有多少机器人? Input Format 一行两个数整数N, M (  1≤N,M < 2^31) Output Format 一个整数K表示至少有K个人 Hint 想不出来的同学... 不要想得太复杂了... Sample Input 2 2 Sample Outpu

pandas学习(常用数学统计方法总结、读取或保存数据、缺省值和异常值处理)

pandas学习(常用数学统计方法总结.读取或保存数据.缺省值和异常值处理) 目录 常用数学统计方法总结 读取或保存数据 缺省值和异常值处理 常用数学统计方法总结 count 计算非NA值的数量 describe 针对Series或DataFrame列计算统计 min/max/sum 计算最小值 最大值 总和 argmin argmax 计算能够获取到最小值和最大值的索引位置(整数) idxmin idxmax 计算能够获取到最小值和最大值的索引值 quantile 计算样本的分位数(0到1)

统计题2

来自可汗统计课40: You sample 36 apples from your farm's harvest of over 200000 apples. The mean weight of the sample is 112 grams(with a 40 gram sample standard deviation). What is the probability that the mean weight of all 200000 apples is within 100 and

poj 3940 Grey Area 浮点输出控制

水题,直接贴代码,注意几种控制浮点输出的方法:e格式,以指数形式输出实数.g格式:自动选f格式或e格式中较短的一种输出,且不输出无意义的零. 代码: //poj 3940 //sep9 #include <iostream> using namespace std; const int maxL=64; int cnt[maxL+10]; double color[maxL]; double area[maxL]; int main() { double p=0.10000; int n,w;