PAT_A1104#Sum of Number Segments
Source:
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的更多相关文章
- PAT1107:Sum of Number Segments
1104. Sum of Number Segments (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Pen ...
- PAT Sum of Number Segments[数学问题][一般]
1104 Sum of Number Segments(20 分) Given a sequence of positive numbers, a segment is defined to be a ...
- PAT 甲级 1104 sum of Number Segments
1104. Sum of Number Segments (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Pen ...
- PAT甲级——1104 Sum of Number Segments (数学规律、自动转型)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90486252 1104 Sum of Number Segmen ...
- 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 ...
- A1104. Sum of Number Segments
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For exam ...
- 1104 Sum of Number Segments(20 分)
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For exam ...
- PAT 1104 Sum of Number Segments
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For exam ...
- PAT甲级——A1104 Sum of Number Segments【20】
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
随机推荐
- 九条命令检查Linux服务器性能
一.uptime命令 这个命令可以快速查看机器的负载情况.在Linux系统中,这些数据表示等待CPU资源的进程和阻塞在不可中断IO进程(进程状态为D)的数量.这些数据可以让我们对系统资源使用有一个宏观 ...
- 判断是否是NaN
if (isNaN(parseInt(x))) { alert("非数字"); } else{ alert("数字"); }
- Dubbo 系列(07-5)集群容错 - Mock
Dubbo 系列(07-5)集群容错 - Mock [toc] Spring Cloud Alibaba 系列目录 - Dubbo 篇 1. 背景介绍 相关文档推荐: Dubbo 实战 - 服务降级 ...
- 常用缓存淘汰算法(LFU、LRU、ARC、FIFO、MRU)
缓存算法是指令的一个明细表,用于决定缓存系统中哪些数据应该被删去. 常见类型包括LFU.LRU.ARC.FIFO.MRU. 最不经常使用算法(LFU): 这个缓存算法使用一个计数器来记录条目被访问的频 ...
- $vim$配置以及$linux$
vim的配置 1 set nu "设置行标号 2 set tabstop=4 "这一条以及以下三条都把缩进设为4 3 set shiftwidth=4 4 set softtabs ...
- 删除文件时提示“找不到该项目”,怎么解决? 转摘自:http://jingyan.baidu.com/article/e4d08ffdf5ab470fd2f60df4.html
故障现象:在使用Windows系统删除文件或者文件夹的时候,有时会出现“找不到该项目”的错误提示,可能再次“重试”也无济于事. 那么,接下来T库小编就为库友们简单概括一下出现该问题的原因. 故障原因: ...
- 从一个Activity打开另外一个Activity
public class MainActivity extends Activity { /** Called when the activity is first created. */ @Over ...
- react学习笔记_03-组件&props
组件 & Props的学习 组件允许你将 UI 拆分为独立可复用的代码片段,并对每个片段进行独立构思. 组件,从概念上类似于 JavaScript 函数.它接受任意的入参(即 “props”) ...
- C# 编程--数组
数组 可以帮我我们一次声明存储多个相同类型的变量.用来解决同一类大量数据在内存存储和运算的功能特点:连续.同一类数据数组定义==>赋值==>取值 定义: int[] n ...
- Tomcat8.0源码编译
最近打算开始研究一下Tomcat的工作原理,拜读一下源码.所以先从编译源码开始了.尽管网上有那么多的资料,但是总是觉得,自己研究一遍,写一遍,在动手做一遍能够让我们更加深入的了解.现在整个社会都流行着 ...