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<iostream>
#include<vector>
#include<iomanip>
using namespace std;
int main(){
int N;
cin>>N;
double sum=0.00;
vector<double> vi(N,0);
for(int i=0; i<N; i++)
cin>>vi[i];
for(int i=1; i<=vi.size(); i++)
sum+=vi[i-1]*(i)*(N-i+1);
cout<<setiosflags(ios::fixed)<<setprecision(2)<<sum<<endl;
return 0;
}

PAT 1104 Sum of Number Segments的更多相关文章

  1. PAT 甲级 1104 sum of Number Segments

    1104. Sum of Number Segments (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Pen ...

  2. PAT甲级——1104 Sum of Number Segments (数学规律、自动转型)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90486252 1104 Sum of Number Segmen ...

  3. PAT 甲级 1104. Sum of Number Segments (20) 【数学】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1104 思路 最容易想到的一个思路就是 遍历一下所有组合 加一遍 但 时间复杂度 太大 会超时 ...

  4. PAT (Advanced Level) 1104. Sum of Number Segments (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  5. PAT甲题题解-1104. Sum of Number Segments (20)-(水题)

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  6. 【PAT甲级】1104 Sum of Number Segments (20 分)

    题意:输入一个正整数N(<=1e5),接着输入N个小于等于1.0的正数,输出N个数中所有序列的和. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC ...

  7. PAT A1104 Sum of Number Segments (20 分)——数学规律,long long

    Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For exam ...

  8. 1104 Sum of Number Segments(20 分)

    Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For exam ...

  9. 1104 Sum of Number Segments

    题意: 给出n个不大于1.0的小数序列,如{ 0.1, 0.2, 0.3, 0.4 },则共有10个分片(0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, ...

随机推荐

  1. Timus 1146. Maximum Sum

    1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive ...

  2. eclipse和jdk版本对应问题

    日常开发中,32位eclipse要用32位jdk,64位则必须要用64位jdk,否则启动时就会报错,load jvm.dll失败,昨天又遇到了这个问题.更换对应的版本之后就好了.tomcat等应用也有 ...

  3. 使用centos 5.x 32位系统安装astgo 2014 v7.0教程(含全套安装文件)

    版本特色: 全自动安装 安装过程中不用频繁输入yes或回车 自带完整号码归属地数据库 自带触屏版WAP ·首先确定你需要使用astgo 2014 7.0还是7.3: astgo 2014 v 7.0 ...

  4. kmp的练习们

    //poj3461 Oulipo //kmp模板 统计子串在母串中的位置 #include<iostream> #include<cstdio> #include<cst ...

  5. [App Store Connect帮助]三、管理 App 和版本(2.2)输入 App 信息:设置 App 分级

    您必须设置 App 分级,这是一项平台版本信息属性,用于在 App Store 上实施家长控制.App Store Connect 提供了一份内容描述列表,通过该列表,您可以确定相应内容在您 App ...

  6. 高德,百度,Google地图定位偏移以及坐标系转换

    一.在进行地图开发过程中,我们一般能接触到以下三种类型的地图坐标系: 1.WGS-84原始坐标系 一般用国际GPS纪录仪记录下来的经纬度,通过GPS定位拿到的原始经纬度,Google和高德地图定位的的 ...

  7. 免费开源ERP成功案例分享:化学之家通过Odoo实现工业互联网转型

    本文来自<开源智造Odoo客户成功案例采访实录>的精选内容章节.请勿转载.欢迎您反馈阅读意见. 客户地区:江苏常州 客户名称:化学之家(中外合资) 所属行业:化工制造(工业) 实施模块:销 ...

  8. tomcat解决 java.lang.IllegalArgumentException: Request header is too large

    tomcat运行项目时,有一个请求过去后,后台报这样的错java.lang.IllegalArgumentException: Request header is too large 原因:请求头超过 ...

  9. Mac上随时切换PYTHON版本

    在MAC上,默认安装了python2.*,自己又安装了python3.*:假如我们需要在终端上随时切换python控制台到需要的版本,可以采用下面的方法. 1.用命令   sudo vi ~/.bas ...

  10. c#异步多线程

    1.asyncrel = delegate.BeginInvoke实现委托异步调用. 2.异步等待 asyncrel.IsCompleted用于判断是否执行完毕 or EndInvoke用于等待执行完 ...