1104. Sum of Number Segments (20)
来源:互联网 发布:斗鱼 知乎 编辑:程序博客网 时间:2024/06/05 15:10
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:40.1 0.2 0.3 0.4Sample Output:
5.00
#include<iostream>#include<cstdio>using namespace std;int main(){ int n; double sum=0,num; cin>>n; for(int i=0;i<n;i++) { cin>>num; sum+=num*(n-i)*(i+1); } printf("%.2f",sum); return 0;}
- 【PAT】1104. Sum of Number Segments (20)
- 1104. Sum of Number Segments (20)
- 1104. Sum of Number Segments (20)
- 1104. Sum of Number Segments (20)
- PAT 1104. Sum of Number Segments (20)
- 1104. Sum of Number Segments (20)
- 1104. Sum of Number Segments (20)
- PAT 1104. Sum of Number Segments (20)
- 1104. Sum of Number Segments (20)
- [pat]1104. Sum of Number Segments (20)
- 1104. Sum of Number Segments (20)
- 1104. Sum of Number Segments (20)
- 1104. Sum of Number Segments (20)
- 1104. Sum of Number Segments (20)
- 1104. Sum of Number Segments (20)
- PAT 1104. Sum of Number Segments (20)
- 1104. Sum of Number Segments (20)
- 1104.Sum of Number Segments (20)
- python升级导致yum命令无法使用的解决办法(修改版)
- Gradle sync failed: Plugin with id 'com.novoda.bintray-release' not found
- WebGIS学习(三)WebGIS前端地图显示之根据地理范围换算出瓦片行列号的原理(核心)
- Linux--shell中字符串的截取
- 面向对象的基本概念
- 1104. Sum of Number Segments (20)
- node.js 探索之路(听课笔记——基础一)
- 解决AFNetWorking 请求数据报”Request failed: unacceptable content-type: text/plain” 错误
- CodeForces 672D Robin Hood(二分)
- sklearn文档 — 1.5. 随机梯度下降
- React-Router入门Demo
- lua luajit 安装cjson
- github+hexo搭建免费博客
- [模板]