Source:

PAT A1104 Sum of Number Segments (20 分)

Description:

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

Key:

  • 模拟题

Attention:

  • i*(n-i+1)*x,3和4测试点会报错

Code:

 #include<cstdio>

 int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n;
double x,sum=;
scanf("%d", &n);
for(int i=; i<=n; i++)
{
scanf("%lf", &x);
sum += (x*i*(n-i+));
}
printf("%.2f\n", sum); return ;
}

PAT_A1104#Sum of Number Segments的更多相关文章

  1. PAT1107:Sum of Number Segments

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

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

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

  3. PAT 甲级 1104 sum of Number Segments

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

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

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

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

  6. A1104. Sum of Number Segments

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

  7. 1104 Sum of Number Segments(20 分)

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

  8. PAT 1104 Sum of Number Segments

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

  9. 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​​ ...

随机推荐

  1. CSS属性去除图片链接时的虚线框

    CSS 之outline (轮廓)是绘制于元素周围的一条线,位于边框边缘的外围,可起到突出元素的作用.outline 属性是一个简写属性,用于设置元素周围的轮廓线.注释:轮廓线不会占据空间,也不一定是 ...

  2. Java + selenium window()接口方法介绍

    在浏览器启动的代码中,有一段关于window接口的调用,这篇文章就是来解释介绍这个接口的.代码如下 driver.manage().window().maxmize(); window接口主要是用来控 ...

  3. C语言|博客作业6

    一.本周教学内容&目标 第3章 分支结构 3.1-3.2 使学生熟悉多分支结构.字符型数据类型和逻辑运算符. 二.本周作业头 问题 答案 这个作业属于那个课程 C语言程序设计II 这个作业要求 ...

  4. sublime text3中使用PHP编译系统

    前言: php是服务器端语言,我们平时写的php代码想要查看运行结果的话,通常会搭建web服务器,然后通过浏览器访问.而对于有时候一些简单的测试代码来说,此过程就有点繁琐了.编译系统的好处是,可以让我 ...

  5. sql优化 分字段统计查询

    select count(1) from pd_xxx_origin_xxx_data where create_time like '2019-02-23%' and source='20036' ...

  6. C++ 中的 const、引用和指针的深入分析

    1,关于 const 的疑问: 1,const 什么时候为只读变量,什么时候是常量: 1,const 从 C 到 C++ 进化的过程中得到了升级,const 在 C++ 中不仅仅像在 C 中声明一个只 ...

  7. mac 支持rz sz

    安装 lrzsz brew install lrzsz 配置 iTerm2 安装完成后我们需要在 iTerm2 中使用的话,还需要一些配置 进入到 /usr/local/bin 目录下,下载两个脚本文 ...

  8. Java开发中的23种设计模式详解(2)结构型

    我们接着讨论设计模式,上篇文章我讲完了5种创建型模式,这章开始,我将讲下7种结构型模式:适配器模式.装饰模式.代理模式.外观模式.桥接模式.组合模式.享元模式.其中对象的适配器模式是各种模式的起源,我 ...

  9. js常用算术运算符与一元运算符在做运算时不同类型的转换规则

    /** * 算术运算符:+, -, *, /, % * 当对非number类型的值进行运算(-, *, /, %)时,会将这些值先转换成number再运算,加法'+'运算除外, * 当对非number ...

  10. linux100day(day8)--shell监控脚本练习

    这是一个大型的监控脚本,方便于查看硬盘,网络,负载,内核版本等系统信息. 本脚本来自于github的atarallo,我对脚本做出了改编和一些注释,尽量让新手也能理解,这个脚本逻辑清楚简单,适合用于练 ...