uva 10883——Supermean
Do you know how to compute the mean (or average) of n numbers? Well, that's not good enough for me. I want the supermean! "What's a supermean," you ask? I'll tell you. List the n given numbers in non-decreasing order. Now compute the average of each pair of adjacent numbers. This will give you n - 1 numbers listed in non-decreasing order. Repeat this process on the new list of numbers until you are left with just one number - the supermean. I tried writing a program to do this, but it's too slow. :-( Can you help me?
Input
The first line of input gives the number of cases, N. N test cases follow. Each one starts with a line containing n (0<<b>n<=50000). The next line will contain the ninput numbers, each one between -1000 and 1000, in non-decreasing order.
Output
For each test case, output one line containing "Case #x:" followed by the supermean, rounded to 3 fractional digits.
Sample Input
4
1
10.4
2
1.0 2.2
3
1 2 3
5
1 2 3 4 5
Sample Output
Case #1: 10.400
Case #2: 1.600
Case #3: 2.000
Case #4: 3.000
题意:给出n个数字, 要求你求出它们的supermean, supermean的定义是: n个数先两两相邻求平均值, 那么得到n-1个数, 已知循环做这件事, 直到剩下的数字只有1个, 那么这数就是supermean.
思路:该题在刘汝佳的紫书上《入门经典第二版》上有涉及(具体320页),没有书的也可查看我博客中的uva 1635题,和该题类似,比如假设5个数a1,a2,a3,a4,a5,最后退出的结果是a1+4a2+6a3+4a4+a5,聪明的小伙伴或许已经想到杨辉三角,就是杨辉三角,二项式系数c40到c44,然后去求即可,打不了二维表,对于每个n,打一个一维表,最后一步关键的高精度处理,这里采用取对数用double保存;
code:
#include <iostream>#include <cstdio>#include <vector>#include <cmath>using namespace std; const int N=50011;double f[N]; void my_way(int n) //对于每个n,打一个一维表{ //f[0]=1; f[0]=f[n]=0; for (int i=1;i<=n/2;i++) f[n-i]=f[i]=f[i-1]+log10(n-i+1)-log10(i); //高精度处理1}int main(){ int n,T,ca=1; double ans,a; scanf("%d",&T); while (T--) { scanf("%d",&n); ans=0; my_way(n-1); for (int i=0;i<n;i++) { scanf("%lf",&a); ans+=1.0*pow(10,f[i]-(n-1)*log10(2))*a; //高精度处理2 } printf("Case #%d: %.3lf\n",ca++,ans); }}
uva 10883——Supermean相关推荐
- python读取文件并且排序_python 顺序读取文件夹下面的文件(自定义排序方式)...
我们在读取文件夹下面的文件时,有时是希望能够按照相应的顺序来读取,但是 file_lists=os.listdir()返回的文件名不一定是顺序的,也就是说结果是不固定的.就比如读取下面这些文件,希望能 ...
- [搜索]UVa 129 困难的串
题意:将一个包含两个相邻的重复子串的子串,称为"容易的串",其他为"困难的串". 输入正整数n和l,输出由前l个字符组成的,字典序第n小的困难的串. 输入样例: ...
- uva 401.Palindromes
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- Uva 3767 Dynamic len(set(a[L:R])) 树套树
Dynamic len(set(a[L:R])) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 https://uva.onlinejudge.org/in ...
- UVA 11752 超级幂
UVA 11752 超级幂 Z - The Super Powers Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & ...
- UVa 11174 - Stand in a Line
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa 10112 - Myacm Triangles
UVa第一卷最后一题. 求内部不含点并且面积最大的三角形. 暴力. 代码如下: 1 #include<iostream> 2 #include<cstdio> 3 #inclu ...
- UVa 10180 - Rope Crisis in Ropeland!
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=41&pa ...
- Uva 10074【递推dp】
UVa 10074 题意:求01矩阵的最大子0矩阵. http://www.csie.ntnu.edu.tw/~u91029/MaximumSubarray.html#2 这里说的很清楚.先求Larg ...
最新文章
- php采用fpdf生成中文pdf
- 新一轮光伏电站产能过剩隐忧初显
- 注意服务器系统日期对防病毒软件的影响
- putty保存用户名和密码_使用PuTTY远程登录软件登录 Linux 实例
- 视界云:CDN{内容分发网络} 知识详解
- layui使用弹出层 关闭后弹层的内容又显示出来
- 如何将静态网页部署到github上
- java核心知识点学习----多线程间的数据共享的几种实现方式比较
- 【渝粤题库】 广东开放大学 劳动和社会保障法 形成性考核
- win10以管理员身份解压缩WinRAR文件
- Android 根据手机自带GPS获取当前位置,经纬度
- 利用matlab导入或读取数据至Excel(COM方法和xlswrite,xlsread方法)
- 打字拼音软件测试,学打字练打字
- 保存网页html 有什么,保存网页时HTML和MHTML区别在哪里
- 《经营的本质》1-“经营的基本元素”读后感及读书笔记
- pythonallowpos_基于Python的诗和远方
- golang 字符串转整形 string 转 int ,go string 转 int
- Oracle根据当前时间获取最近5年,最近6个月,最近30天的时间
- 解决VMware Workstation 与 Hyper-V 不兼容。请先从系统中移除 Hyper-V 角色,然后再运行 VMware Workstation。
- 国内医院临床自闭症病例分享:大脑自闭了,为什么是肠道的锅?
热门文章
- 奇妙的 CSS shapes(CSS图形)
- web前端工程师全套教程免费分享
- CORS(跨域资源共享)
- 《Effective Java》读书笔记 Item 1:考虑静态工厂方法,而不是构造器
- js parseInt()与Number()区别
- luogu P2516 [HAOI2010]最长公共子序列
- 控制器中获取Field值
- android /data/data/数据作用,android 清除data/data/ 下其他应用的数据
- java ean13 条形码_【教程】Spire.Barcode 教程:如何在C#中创建EAN-13条码
- java教学楼的属性_java设计一个父类建筑物building,由它派生出教学楼类classroom,然后采用一些数据进行测试....