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

这就是一道找规律题
每个数字出现的次数为(i+1)*(n-i)次
 #include <iostream>
#include <vector>
using namespace std;
int n;
double sum = 0.0;
int main()
{
cin >> n;
double *v = new double[n];
for (int i = ; i < n; ++i)
cin >> v[i];
for (int i = ; i < n; ++i)
sum += v[i] * (i + )*(n - i);
printf("%.2f\n", sum);
return ;
}

PAT甲级——A1104 Sum of Number Segments的更多相关文章

  1. PAT甲级——A1104 Sum of Number Segments【20】

    Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ ...

  2. PAT 甲级 1104 sum of Number Segments

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

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

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

  4. PAT Advanced A1104 Sum of Number Segments (20) [数学问题]

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

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

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

  6. 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 ...

  7. A1104. Sum of Number Segments

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

  8. PAT_A1104#Sum of Number Segments

    Source: PAT A1104 Sum of Number Segments (20 分) Description: Given a sequence of positive numbers, a ...

  9. PAT Sum of Number Segments[数学问题][一般]

    1104 Sum of Number Segments(20 分) Given a sequence of positive numbers, a segment is defined to be a ...

随机推荐

  1. 将sparkStreaming结果保存到Redshift数据库

    1.保存到redshift数据库的代码 package test05 import org.apache.log4j.{Level, Logger}import org.apache.spark.rd ...

  2. 常用的JS方法(见到好的就添加进来)

    // 悬浮置顶 ; (function ($) { $.fn.crumbsFixedPosition = function (options) { var defaults = { cName: 'f ...

  3. PHP算法之Z 字形变换

    将一个给定字符串根据给定的行数,以从上往下.从左到右进行 Z 字形排列. 比如输入字符串为 "LEETCODEISHIRING" 行数为 3 时,排列如下: L C I RE T ...

  4. File转换为MultipartFile工具类

    package cn.com.utils; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileu ...

  5. mySql搜索引擎

    转载自 深入浅出mysql数据库 MySQL5.5以后默认使用InnoDB存储引擎,其中InnoDB和BDB提供事务安全表,其它存储引擎都是非事务安全表. 若要修改默认引擎,可以修改配置文件中的def ...

  6. LOIC Download

    { //https://github.com/NewEraCracker/LOIC }

  7. VS 解决方案 Xamarin 配置

    需要额外安装 Mono 程序 工具->Xamarin->Android -> SDK路径  要和 你配置的ANDROID_SDK_ROOT 的路径一至如果没有 ANDROID_SDK ...

  8. 1003CSP-S模拟测试赛后总结

    我是垃圾……我只会骗分. 拿到题目通读一遍,感觉T3(暴力)是个树剖+线段树. 刚学了树刨我这个兴奋啊.然而手懒决定最后再说. 对着T1一顿yyxjb码了个60pts的测试点分治就失去梦想了.(顺便围 ...

  9. duilib教程之duilib入门简明教程6.XML配置界面

    前面那些教程都是为了让小伙伴们从win32.MFC过渡到duilib,让大家觉得duilib不是那么陌生,如果大家现在还对duilib非常陌生的话,那就说明前面的教程做得不好,请大家在下面留言,我会一 ...

  10. django2 restframework put和delete http404错误

    url要写好 比如 ,最后的/一定要加,否则401 'http://127.0.0.1:8000/persons/' + person.id + '/'