麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

1104. Sum of Number Segments (20)-數(shù)學(xué)問題

2019-11-11 05:25:28
字體:
供稿:網(wǎng)友

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) (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 105. 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>const int maxn=100010;double a[maxn];int main(){ int n; double ans=0; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%lf",&a[i]); }// for(int i=0;i<n;i++){//此法會(huì)超時(shí) // for(int j=i;j<n;j++){// ans+=a[j]*(n-j);// }// } for(int i=0;i<n;i++){ ans+=a[i]*(n-i)*(i+1); } printf("%.02lf",ans);}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 国产精品久久久久无码av | 香蕉成人在线观看 | 黄色大片网站在线观看 | 欧美黄色一区 | 99视频观看 | 免费黄网站在线播放 | 免费观看一区二区三区 | 激情小说另类 | 欧美爱爱视频免费看 | 136福利视频 | 国产精品视频在 | 欧美精品 | 午夜视频大全 | 91久久久久久 | 91精品国产日韩91久久久久久360 | 国产91久久精品 | 免费a级网站 | 久夜草 | 国产成人观看 | 亚洲综合一区二区三区 | 久草在线视频福利 | 成人午夜精品久久久久久久3d | 欧美日韩在线播放 | 成人午夜免费福利 | 成年免费视频黄网站在线观看 | 午夜精品毛片 | 日美黄色片 | 一级片999 | 国产精品片一区二区三区 | a网在线| 国产精品久久久久久久久久久久久久久久 | 国产精品野外av久久久 | 久久国产精品二国产精品中国洋人 | xx53xx| 鲁丝片一区二区三区免费入口 | 色吧久久| 欧美一级做一a做片性视频 日韩黄色片免费看 | 亚洲精品一区二区三区在线看 | 精品国产一区二区三区在线观看 | 成人精品一区二区三区中文字幕 | 久草在线综合 |