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. JQuery获取与设置select

    获取select : 1.获取select 选中的 text :    $("#ddlregtype").find("option:selected").tex ...

  2. linux查看日志中特定字符串以及前后信息内容命令

    在项目实施过程中,我们经常会查看日志,更是经常会根据某些特地字符串去查找日志内容. 下面就是日志查找命令: 1.查询字符串命令: cat fileName|grep '要查找的字符串' 实例:cat ...

  3. 【Python—windows 下 virtualEnv 使用】

    用pip安装virtualenv pip3 install virtualenv 在相应的文件夹中创建一个独立的Python运行环境,命名为env. 之后会自动创建一个 env 文件夹,有: Incl ...

  4. Apache Shiro 会话+缓存+记住我(三)

    1.会话管理SessionDao和SessionManager 1)安装Redis 2)依赖 <dependency> <groupId>redis.clients</g ...

  5. python 大小写转换函数

    capitalize() 首字母大写,其余全部小写 upper() 全转换成大写 lower() 全转换成小写 title()  标题首字大写,如"i love python".t ...

  6. java并发编程之美-阅读记录7

    java并发包中的并发队列 7.1ConcurrentLinkedQueue 线程安全的无界非阻塞队列(非阻塞队列使用CAS非阻塞算法实现),其底层数组使用单向列表实现,对于出队和入队操作使用CAS非 ...

  7. 在linux中出现there are stopped jobs 的解决方法【转自:http://www.linuxdiyf.com/viewarticle.php?id=104604】

    在用管理员执行一个命令后,我用Ctrl+Z把命令转移到了后台天.导致我无法退出root的. 输入命令:logout终端显示:There are stopped jobs. 解决方法:输入命令:jobs ...

  8. Linux下tree的使用介绍

    1.在ubuntu系统中默认是没有tree这个命令的,需要安装,用下面的命令就可以安装tree这个命令工具sudo apt-get install tree. 2.首先来说说使用tree这个命令,就是 ...

  9. 横纵方向走马灯滚动,纯javascript代码

    <body onload="beginmarquee()"> <table width="1024" border="0" ...

  10. 浅谈maven自动化构建工具

    转载https://blog.csdn.net/zxm1306192988/article/details/76209062 Maven是什么[what] 1.Maven 是 Apache 软件基金会 ...