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 ...
随机推荐
- 练习1-20 编写程序detab,将输入中的制表符替换成适当数目的空格.
1.问题描述 编写程序detab,将输入中的制表符替换成适当数目的空格,使空格充满到下一个制表符终止位的地方. 假设制表符终止位的位置是固定的, 换句话说每隔n列就会出现一个制表符终止位. 2.描述 ...
- day 109结算中心.
from django.db import models from django.contrib.contenttypes.fields import GenericForeignKey,Generi ...
- SQLServer2008不允许保存更改
sql server 2008在更改表结构的时候提示 “不允许保存更改,您所做的更改要求删除并重新创建以下表” 解决方案: 1.一般情况下:工具--选项--Designers--表设计器和数据库设计器 ...
- 关于曲线 规划 算法 线性 S曲线 贝塞尔曲线
工控领域经常会涉及速度加减速的算法:线性加减速,S曲线加减速(sin函数,拓展其他三角函数曲线), 贝塞尔曲线,等等. 线性加减速: 设定起始速度V0,目标速度V1,加速时间Ta(s,或加速度) ...
- JavaScript Set
function Set() { var items = {}; this.has = function(value) { return value in items } this.add = fun ...
- 不小心执行了 rm -f,先别急着跑路
作者:justmine http://www.cnblogs.com/justmine/p/10359186.html 前言 每当我们在生产环境服务器上执行rm命令时,总是提心吊胆的,因为一不小心执行 ...
- python面试题之有没有一个工具可以帮助查找python的bug和进行静态的代码分析?
pycheck pylint 本文首发于python黑洞网,博客园同步更新
- 50-python基础-python3-列表-函数sorted() 对列表进行临时排序
sorted()函数对列表进行临时排序,返回排序后的列表: 区别列表方法sort()原地修改,无返回值. 1-要保留列表元素原来的排列顺序,同时以特定的顺序呈现它们,可使用函数sorted() . 2 ...
- RabbitMq--2--安装
简单说下个人的理解,mq就是一个消息代理,负责异步消息转发,可以很大程度缓解服务器压力,并且防止服务器宕机影响业务等. 安装: 环境:centos7 1).首先需要安装erlang #wget htt ...
- 《零基础学习Python制作ArcGIS自定义工具》课程简介
Python for ArcGIS Python for ArcGIS是借助Python语言实现ArcGIS自动化行为的综合,它不止是如课程标题所述的“制作ArcGIS自定义工具”,还包括使用Pyth ...