Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence { 0.1, 0.2, 0.3, 0.4 }, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0.4) (0.3) (0.3, 0.4) and (0.4).

Now given a sequence, you are supposed to find the sum of all the numbers in all the segments. For the previous example, the sum of all the 10 segments is 0.1 + 0.3 + 0.6 + 1.0 + 0.2 + 0.5 + 0.9 + 0.3 + 0.7 + 0.4 = 5.0.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N, the size of the sequence which is no more than 1. The next line contains N positive numbers in the sequence, each no more than 1.0, separated by a space.

Output Specification:

For each test case, print in one line the sum of all the numbers in all the segments, accurate up to 2 decimal places.

Sample Input:

4
0.1 0.2 0.3 0.4

Sample Output:

5.00
#include<cstdio>
int main(){
int n;
scanf("%d",&n);
double v,ans = ;
for(int i = ; i <= n; i++){
scanf("%lf",&v);
ans += v * i * (n + - i);
}
printf("%.2f",ans);
return ;
}

最新文章

  1. Reading C type declarations(引用http://unixwiz.net/techtips/reading-cdecl.html)
  2. 变通实现微服务的per request以提高IO效率
  3. Linux 系统中僵尸进程
  4. 如何自定义jupyter notebook的主题
  5. 深入理解HTML表格
  6. 商业银行在CNAPS体系中对各种交易的处理
  7. java-二维码编写zxing
  8. hdu-5904 LCIS(水题)
  9. jdbc 得到表结构、主键
  10. Sublime text插件使用技巧
  11. hdu 2028
  12. Java theory and practice
  13. springmvc的3中路径风格
  14. Daily Scrum 12.7
  15. 在linux环境下配置node:node + npm + forever
  16. 在MAC中安装Compass的方法 (转)
  17. 一份传世典文:十年编程(Teach Yourself Programming in Ten Years)
  18. nginx、php-fpm默认配置与性能–TCP socket还是unix domain socket【转】
  19. 通过钩子程序跨程序关闭Window
  20. CMDB资产管理系统开发【day26】:admin action

热门文章

  1. windows 2013 datacenter 安装sql server2008 r2兼容性
  2. poj 1658 Eva&#39;s Problem(水题)
  3. PTA实验作业-01
  4. 【转】 Pro Android学习笔记(三二):Menu(3):Context菜单
  5. hdu 1506 单调栈问题
  6. 左连接,右连接,内连接,Union
  7. HTML5小知识
  8. 任务调度TimerTask&amp;Quartz的 Java 实现方法与比较
  9. C#笔记(二)
  10. 4、linux-grep awk sed and cuf sort uniq join