PAT甲级——A1104 Sum of Number Segments
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这就是一道找规律题
每个数字出现的次数为(i+1)*(n-i)次
#include <iostream>
#include <vector>
using namespace std;
int n;
double sum = 0.0;
int main()
{
cin >> n;
double *v = new double[n];
for (int i = ; i < n; ++i)
cin >> v[i];
for (int i = ; i < n; ++i)
sum += v[i] * (i + )*(n - i);
printf("%.2f\n", sum);
return ;
}
PAT甲级——A1104 Sum of Number Segments的更多相关文章
- PAT甲级——A1104 Sum of Number Segments【20】
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
- 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 Advanced A1104 Sum of Number Segments (20) [数学问题]
题目 Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For e ...
- PAT 甲级 1104. Sum of Number Segments (20) 【数学】
题目链接 https://www.patest.cn/contests/pat-a-practise/1104 思路 最容易想到的一个思路就是 遍历一下所有组合 加一遍 但 时间复杂度 太大 会超时 ...
- 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 ...
- PAT_A1104#Sum of Number Segments
Source: PAT A1104 Sum of Number Segments (20 分) Description: Given a sequence of positive numbers, a ...
- PAT Sum of Number Segments[数学问题][一般]
1104 Sum of Number Segments(20 分) Given a sequence of positive numbers, a segment is defined to be a ...
随机推荐
- Linux sed命令实现替换文本内容
/root/data/code-s3201/publish_codex/deploy/db.properties db.properties中的 1.0.0.6 替换为 1.0.0.7 sed -i ...
- VBA当中的时间日期函数
目前还没发现VBA中有直接的函数能够将完整的年月日时分秒的文本格式日期转换成日期型日期的,那只能使用间接实现的办法.用dateserial + timeserial的方法.因为dateserial和t ...
- 浏览器自带记忆功能,使input颜色和字体丢失
方法一 : 会有视觉上颜色的变化input:-internal-autofill-selected { /*内置阴影填充 背景颜色*/ box-shadow: inset 0 0 0 1000px # ...
- JAVA数据结构之哈希表
Hash表简介: Hash表是基于数组的,优点是提供快速的插入和查找的操作,编程实现相对容易,缺点是一旦创建就不好扩展,当hash表被基本填满的时候,性能下降非常严重(发生聚集引起的性能的下降),而且 ...
- thinkphp5+GatewayWorker+Workerman
项目地址 ttps://www.workerman.net/workerman-chat thinkphp5+GatewayWorker+Workerman聊天室,可以多人聊天,指定某个人进行聊天, ...
- CIE XYZ
了解CIE XYZ的来龙去脉,看维基之前,先读这两篇文章: https://medium.com/hipster-color-science/a-beginners-guide-to-colorime ...
- 阿里云POLARDB如何帮助猿辅导打造“孩子喜欢老师好”的网课平台?
海量的题库.音视频答题资料.用户数据以及日志,对猿辅导后台数据存储和处理能力都提出了严峻的要求.而由于教育辅导行业的业务特点,猿辅导也面临着业务峰值对于数据库能力的巨大挑战.本文就为大家介绍阿里云PO ...
- 概率dp的迭代方式小结——zoj3329,hdu4089,hdu4035
在推导期望方程时我们常常会遇到dp[i]和其他项有关联,那么这时候我们就难以按某个顺序进行递推 即难以通过已经确定的项来求出新的项 即未知数的相互关系是循环的 但是我们又可以确定和dp[i]相关联的项 ...
- golang中time包的使用
一.代码 package main; import ( "time" "fmt" ) func main() { //time.Time代表一个纳秒精度的时间点 ...
- jquery学习笔记(五):AJAX
内容来自[汇智网]jquery学习课程 5.1 ajax AJAX 是与服务器交换数据的艺术,它在不重载全部页面的情况下,实现了对部分网页的更新. AJAX = 异步 JavaScript 和 XML ...