首页 > 其他分享 >1104 Sum of Number Segments

1104 Sum of Number Segments

时间:2022-11-19 02:33:08浏览次数:37  
标签:sequence 0.1 0.3 0.2 0.4 1104 numbers Sum Segments

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 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<stdio.h>

double seq[100005];
int count[100005];

int main()
{
    double sum=0;
    long long int num;
    scanf("%lld",&num);
    for(int i=0;i<num;i++)
    {
        scanf("%lf",&seq[i]);
        sum+=(i+1)*(num-i)*seq[i];
        
     } 

     printf("%.2f",sum);
 } 

 



标签:sequence,0.1,0.3,0.2,0.4,1104,numbers,Sum,Segments
From: https://www.cnblogs.com/zzzlight/p/16905369.html

相关文章

  • POJ 1845Sumdiv(数论)
    SumdivTimeLimit:1000MS MemoryLimit:30000KTotalSubmissions:20041 Accepted:5060DescriptionConsidertwonaturalnumbersAandB.LetSbethesumof......
  • 38:列表_排序_revered逆序_max_min_sum
    ###列表排序###修改原列表,不建新列表的排序>>>a=[20,10,30,40]>>>id(a)46017416>>>a.sort()#默认是升序排列>>>a[10,20,30,40]>>>a=[10,20,30,40]>>......
  • 【补题】The 2022 SDUT Summer Trials
    比赛链接The2022SDUTSummerTrialsA.Ginger'snumber样例恶臭(恼)签到题简单分解因数就会发现要求的就是\(gcd\),直接算即可,时间复杂度\(\Theta(Tlog(max(x,y)))\)......
  • 《Weakly Sumpervised cell instance segmentation by propagating from detection re
    1.介绍非侵入式的显微镜(共焦距)细胞技术广泛的用于细胞计数和形状分析,不需要对切片进行上色。对单独细胞的分割任务是细胞图像分析中的重要一环。然而,细胞的分割及其困难,......
  • PTA_Maximum Subsequence Sum
    Givenasequenceof K integers{ N1​, N2​,..., NK​ }.Acontinuoussubsequenceisdefinedtobe{ Ni​, Ni+1​,..., Nj​ }where 1≤i≤j≤K.......
  • CF631E Product Sum
    前言不知道为什么题解里的李超线段树都要分两种情况讨论,我觉得的大可不必,其实一遍就好了。分析设\(ans_i\)为\(i\)移动到其他位置时获得的最大取值,\(sum_i\)为\(......
  • [Dubbo] 整理 简化 配置Provider和Consumer(SpringBoot + Dubbo + Zookeeper 搭建环境)
    SpringBoot+Dubbo+Zookeeper搭建环境Dubbo2.7使用的AlibabaDubbo,后来@Service等注解被标识@Deprecated。现改用Dubbo3.0.6,出现了一些版本匹配的问题。可以......
  • LeetCode 167.TowSum
    双指针classSolution{public:vector<int>twoSum(vector<int>&numbers,inttarget){intl=0,r=numbers.size()-1,sum=0;while(l<r){......
  • 64. Minimum Path Sum
    Givena m x n gridfilledwithnon-negativenumbers,findapathfromtoplefttobottomrightwhich minimizes thesumofallnumbersalongitspath.No......
  • kafka-consumer-groups 命令行工具使用手册,Kafka 管理必备
    kafka-consumer-groups命令行工具使用手册该手册原文出自​​$KAFKA_HOME\bin\windows\kafka-consumer-groups.bat--help​​命令的输出结果,并由​​Redisant​​提供......