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. java知识点拾遗:)

    一篇有用的java基础知识总结http://www.cnblogs.com/xuwujing/p/8638329.html 枚举:http://blog.csdn.net/qq_27093465/ar ...

  2. node_exporter + grafana

    监控服务器CPU.内存.磁盘.I/O等信息,首先需要安装node_exporter.node_exporter的作用是用于机器系统数据收集. 下载安装: https://github.com/prom ...

  3. jQuery判断checkbox是否选中及获取选中值

    方法一:if ($("#checkbox-id")get(0).checked) {    // do something} 方法二:if($('#checkbox-id').is ...

  4. 中介者模式(Mediator Pattern)

    用于减少多个对象或类之间的通信复杂性. 此模式提供了一个中介类,它通常处理不同类之间的所有通信,并支持通过松散耦合来维护代码.中介者模式属于行为模式类别. 实现实例 在这里通过一个聊天室的示例来演示中 ...

  5. VS2013编译程序出现error C4996: 'std::_Fill_n': Function call with parameters that may be unsafe

    最近按照BiliBil网站Visual C++网络项目实战视频教程,使用VS2013编写一个基于MFC的对话框程序HttpSourceViewer,采用了WinHttp库.Boost xpressiv ...

  6. APACHE两种域名跳转法简单完成重定向

    当我们变更网站域名,或者申请多个域名指向一个网站的时候,这个时候我们就会用到域名跳转(或者叫域名重定向redirect.域名转向).下面用最简单的文字讲两种apache的域名跳转方法. 假设我们想把w ...

  7. Vue内敛模板

    在学习<Vue实战>一书时,学习到组件高级应用-内联模板这一小节时,照着书上的例子敲了一遍,发现未达到预期,切报错. 书上源代码如下: <!DOCTYPE html> < ...

  8. 使用Surface View来显示图片

    public class YUVImageView extends SurfaceView { private static final String TAG = "YUVImageView ...

  9. GenXus学习笔记——Transaction的建立

    我们上次聊到 如何正确无误的的创建一个项目KB 那么这次我们就该聊一点实际的东西了(敲黑板( ̄▽ ̄))  上回书说道我们在创建完自己的KB后 该创建自己的数据库了 首先我们先创建创建一个表 但是创建之 ...

  10. linux用户的基本操作2 用户密码管理

    目录 linux系统的基本用户操作2 用户的扩展知识 用户密码管理 linux系统的基本用户操作2 3)使用userdel删除账户 语法 : userdel [-r] username -r 同时删除 ...